How to get case accurate path on windows

56 views
Skip to first unread message

Chad_Fox

unread,
Oct 28, 2016, 3:39:13 PM10/28/16
to Python Programming for Autodesk Maya
Hi all,

I'd like to confirm if the paths written in maya (on windows) has the correct character case. In otherwords I need to verify the path is good for use on Linux.

I have the following solution, but glob is ... not very fast. 

Would like to know if anyone here has come accross an effective/fast solution for this problem.

import glob
import re
import os

def fix_path_case( path ):
   case_on_disk_path = glob.glob( re.sub( r'([^:])(?=[/\\]|$)', r'[\1]' , path ) )[0]
   slash_fixed_path =  os.path.realpath(case_on_disk_path )
   return slash_fixed_path
   
# Real path on disk is      ''W:/Shows/Proj/Pub/TEX/Proj_skin_DIF.1001.TIF'
bad_case_texture_path = 'W:/shOws/PRoj/PUB/tex/proj_skin_DIF.1001.tif' #path in maya

fixed_path = fix_path_case( path = bad_case_texture_path )



Thanks!

Chad

Justin Israel

unread,
Oct 28, 2016, 9:21:57 PM10/28/16
to python_in...@googlegroups.com
Part of this problem, for me, would be something I would think to solve through conventions at a facility. Are people actually using whatever casing they feel like as opposed to what matches on disk? Is it really a concern about the filename portion, or just a naming issue with the mount points between Windows and Linux? And also, what is the logic of your regex that you hope to express?

It would be difficult to know exactly what to transform the string into, without also doing a glob of the filesytem. If people are allowed to use any caseing they want, then you don't really have a choice but to stat the directory and case-insensitive match the files with your string.

Justin
 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/11dfb149-d63d-4f1b-88d0-c02de401e86e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chad_Fox

unread,
Oct 31, 2016, 2:09:47 PM10/31/16
to Python Programming for Autodesk Maya
This issue is definitely due to the lack of conventions or tools and the solution I have now is just a stop-gap until asset management tools are made to control these paths. 

The entire path is an issue too because we have people manually editing their file paths in maya entering the wrong case in some dir names.

Anywho. The regex searches for all characters except ':' and replaces everything it finds with the second argument [\1] which backmatches the same results, except the results are from what glob sees rather than whats in the original string provided to the re.sub.


On Friday, October 28, 2016 at 6:21:57 PM UTC-7, Justin Israel wrote:
On Sat, Oct 29, 2016 at 8:39 AM Chad_Fox <chadl...@gmail.com> wrote:
Hi all,

I'd like to confirm if the paths written in maya (on windows) has the correct character case. In otherwords I need to verify the path is good for use on Linux.

I have the following solution, but glob is ... not very fast. 

Would like to know if anyone here has come accross an effective/fast solution for this problem.

import glob
import re
import os

def fix_path_case( path ):
   case_on_disk_path = glob.glob( re.sub( r'([^:])(?=[/\\]|$)', r'[\1]' , path ) )[0]
   slash_fixed_path =  os.path.realpath(case_on_disk_path )
   return slash_fixed_path
   
# Real path on disk is      ''W:/Shows/Proj/Pub/TEX/Proj_skin_DIF.1001.TIF'
bad_case_texture_path = 'W:/shOws/PRoj/PUB/tex/proj_skin_DIF.1001.tif' #path in maya

fixed_path = fix_path_case( path = bad_case_texture_path )



Thanks!

Chad

Part of this problem, for me, would be something I would think to solve through conventions at a facility. Are people actually using whatever casing they feel like as opposed to what matches on disk? Is it really a concern about the filename portion, or just a naming issue with the mount points between Windows and Linux? And also, what is the logic of your regex that you hope to express?

It would be difficult to know exactly what to transform the string into, without also doing a glob of the filesytem. If people are allowed to use any caseing they want, then you don't really have a choice but to stat the directory and case-insensitive match the files with your string.

Justin
 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Oct 31, 2016, 4:51:26 PM10/31/16
to python_in...@googlegroups.com
On Tue, Nov 1, 2016 at 7:09 AM Chad_Fox <chadl...@gmail.com> wrote:
This issue is definitely due to the lack of conventions or tools and the solution I have now is just a stop-gap until asset management tools are made to control these paths. 

The entire path is an issue too because we have people manually editing their file paths in maya entering the wrong case in some dir names.

Anywho. The regex searches for all characters except ':' and replaces everything it finds with the second argument [\1] which backmatches the same results, except the results are from what glob sees rather than whats in the original string provided to the re.sub.

Hmm, I was getting strange behaviour from that regex when I gave it a test. It seemed to just replace the character before each / with brackets:

/some/path/to/file.ext => /som[e]/pat[h]/t[o]/file.ex[t] 

Anyways, maybe this would be a better approach?

Here is a slight tweak to account for windows drives:


import os 
import glob
from itertools import imap 

def insensitive_glob(pattern):
    def either(c):
        return '[%s%s]' % (c.lower(),c.upper()) if c.isalpha() else c

    drive, path = os.path.splitdrive(path)
    path = ''.join(map(either, path))

    return glob.glob(os.path.join(drive, path))
 
At least you can avoid a regex?

Justin



On Friday, October 28, 2016 at 6:21:57 PM UTC-7, Justin Israel wrote:
On Sat, Oct 29, 2016 at 8:39 AM Chad_Fox <chadl...@gmail.com> wrote:
Hi all,

I'd like to confirm if the paths written in maya (on windows) has the correct character case. In otherwords I need to verify the path is good for use on Linux.

I have the following solution, but glob is ... not very fast. 

Would like to know if anyone here has come accross an effective/fast solution for this problem.

import glob
import re
import os

def fix_path_case( path ):
   case_on_disk_path = glob.glob( re.sub( r'([^:])(?=[/\\]|$)', r'[\1]' , path ) )[0]
   slash_fixed_path =  os.path.realpath(case_on_disk_path )
   return slash_fixed_path
   
# Real path on disk is      ''W:/Shows/Proj/Pub/TEX/Proj_skin_DIF.1001.TIF'
bad_case_texture_path = 'W:/shOws/PRoj/PUB/tex/proj_skin_DIF.1001.tif' #path in maya

fixed_path = fix_path_case( path = bad_case_texture_path )



Thanks!

Chad

Part of this problem, for me, would be something I would think to solve through conventions at a facility. Are people actually using whatever casing they feel like as opposed to what matches on disk? Is it really a concern about the filename portion, or just a naming issue with the mount points between Windows and Linux? And also, what is the logic of your regex that you hope to express?

It would be difficult to know exactly what to transform the string into, without also doing a glob of the filesytem. If people are allowed to use any caseing they want, then you don't really have a choice but to stat the directory and case-insensitive match the files with your string.

Justin
 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2106c36f-cdcf-4d35-844b-31b954021d7a%40googlegroups.com.

Chad Fox

unread,
Nov 4, 2016, 4:04:36 PM11/4/16
to Python Programming for Autodesk Maya
Thanks I'll check that out. 

Interestingly my regex is working as I described on my work machine, but fails completely on my laptop with an "index out of range" error. the re.__version__ is the same, but glob .. I can't tell except that glob is coming from maya 2015 on my laptop and maya2016 at work. It may be that glob had some subtle changes to it that effect the search/replace.

In anycase this looks better.

Thanks!


-Chad


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA30SRsFAObm12DM%3Dz1JLTS8ZKv4-s6dtAyx0pd0LWfXUw%40mail.gmail.com.

Chad Fox

unread,
Nov 4, 2016, 4:40:18 PM11/4/16
to Python Programming for Autodesk Maya
I take back my comment that it was failing on my laptop.. I simply had an invalid path that did not exist there. Looks like the original re is working here as I described.

Anyways,  it was nice to get another example of how this can be done and thanks for your help!


-Chad




-Chad


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

Justin Israel

unread,
Nov 4, 2016, 4:51:25 PM11/4/16
to Python Programming for Autodesk Maya


On Sat, 5 Nov 2016, 9:40 AM Chad Fox <chadl...@gmail.com> wrote:
I take back my comment that it was failing on my laptop.. I simply had an invalid path that did not exist there. Looks like the original re is working here as I described.

Hm not sure why I got the non workable results with only parts of the string replaced. 



-Chad


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJ4oLs7JerewjBKSupLQbfPaWq1cm1nPiVratwTH%2BS5NroDiLg%40mail.gmail.com.

Chad Fox

unread,
Nov 4, 2016, 5:29:35 PM11/4/16
to Python Programming for Autodesk Maya
Yeah I'll admit that that is a little disconserting. I tried a bunch of variations on the path being input, including changing slashes, adding double \\ and I never got the same results as you described.  


-Chad




-Chad


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1UEvpU05VaBHxeL8v%2B4Wyn7YrvC%2BuWQFJjH-gManM1jg%40mail.gmail.com.

Justin Israel

unread,
Nov 4, 2016, 10:28:48 PM11/4/16
to python_in...@googlegroups.com
On Sat, Nov 5, 2016 at 10:29 AM Chad Fox <chadl...@gmail.com> wrote:
Yeah I'll admit that that is a little disconserting. I tried a bunch of variations on the path being input, including changing slashes, adding double \\ and I never got the same results as you described.  

I extracted this from your original example:

Output:
W:/shOw[s]/PRo[j]/PU[B]/te[x]/proj_skin_DIF.1001.ti[f]

Is this the expected output?

 


-Chad


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJ4oLs7iR6erc0vMGsEf4MiMQT88Hzcj5S2s988VR%2BfdjC9n4Q%40mail.gmail.com.

Marcus Ottosson

unread,
Nov 5, 2016, 5:27:48 AM11/5/16
to python_in...@googlegroups.com

Sorry if this was implied somewhere, but are you aware that on Windows paths are case-insensitive? That is, it makes no guarantees on preserving case and treats c:\tHIS the same as c:\This.​

Justin Israel

unread,
Nov 5, 2016, 6:33:16 AM11/5/16
to python_in...@googlegroups.com


On Sat, 5 Nov 2016, 10:27 PM Marcus Ottosson <konstr...@gmail.com> wrote:

Sorry if this was implied somewhere, but are you aware that on Windows paths are case-insensitive? That is, it makes no guarantees on preserving case and treats c:\tHIS the same as c:\This.​

I think it was implied in the original question 

"I'd like to confirm if the paths written in maya (on windows) has the correct character case. In otherwords I need to verify the path is good for use on Linux
"

I understood that as it not being a problem on Windows itself because of the case insensitive paths. But not working for those files when accessed through Linux because the paths no longer match case sensitive. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

David Moulder

unread,
Nov 5, 2016, 11:54:55 AM11/5/16
to python_inside_maya

I had to do something similar at freestyle games.  As a games company we were on windows and framestore was linux.  So i had to garantee the case of the wondows file paths.  Instead of doing this type of check.  Everyone had to make assests in maya via our project manager.  It garenteed lower case file paths.  The publish step failed if maya file paths were invalid and offered 1 click fixes for most checks.

Not an answer realy, just an alternate way of coping this linux vs windows path issues.


On 5 Nov 2016 10:33, "Justin Israel" <justin...@gmail.com> wrote:


On Sat, 5 Nov 2016, 10:27 PM Marcus Ottosson <konstr...@gmail.com> wrote:

Sorry if this was implied somewhere, but are you aware that on Windows paths are case-insensitive? That is, it makes no guarantees on preserving case and treats c:\tHIS the same as c:\This.​

I think it was implied in the original question 

"I'd like to confirm if the paths written in maya (on windows) has the correct character case. In otherwords I need to verify the path is good for use on Linux
"

I understood that as it not being a problem on Windows itself because of the case insensitive paths. But not working for those files when accessed through Linux because the paths no longer match case sensitive. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0qr6B1bPtYjW6kj2RoYFTUU%3D5oBHkrqfaiUdC0VL-Kyg%40mail.gmail.com.

Chad Fox

unread,
Nov 6, 2016, 1:18:20 AM11/6/16
to python_inside_maya
Hey Justin,

That is the expected outcome of the regex alone, but I found quite by accident that the regex sub written this way, iters over every character individually within glob so each character is found in the bad case string and the re callback \1 substitutes the found char with whats actually on disk.



On Sat, Nov 5, 2016, 8:54 AM David Moulder <da...@thirstydevil.co.uk> wrote:

I had to do something similar at freestyle games.  As a games company we were on windows and framestore was linux.  So i had to garantee the case of the wondows file paths.  Instead of doing this type of check.  Everyone had to make assests in maya via our project manager.  It garenteed lower case file paths.  The publish step failed if maya file paths were invalid and offered 1 click fixes for most checks.

Not an answer realy, just an alternate way of coping this linux vs windows path issues.

On 5 Nov 2016 10:33, "Justin Israel" <justin...@gmail.com> wrote:


On Sat, 5 Nov 2016, 10:27 PM Marcus Ottosson <konstr...@gmail.com> wrote:

Sorry if this was implied somewhere, but are you aware that on Windows paths are case-insensitive? That is, it makes no guarantees on preserving case and treats c:\tHIS the same as c:\This.​

I think it was implied in the original question 

"I'd like to confirm if the paths written in maya (on windows) has the correct character case. In otherwords I need to verify the path is good for use on Linux
"

I understood that as it not being a problem on Windows itself because of the case insensitive paths. But not working for those files when accessed through Linux because the paths no longer match case sensitive. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABD4PkQmvE%3DMVqyHNctGEWu9JBTdYdcNxBO8qLjZfTGkv7FX3w%40mail.gmail.com.

Justin Israel

unread,
Nov 6, 2016, 2:03:12 AM11/6/16
to python_in...@googlegroups.com
On Sun, Nov 6, 2016 at 6:18 PM Chad Fox <chadl...@gmail.com> wrote:
Hey Justin,

That is the expected outcome of the regex alone, but I found quite by accident that the regex sub written this way, iters over every character individually within glob so each character is found in the bad case string and the re callback \1 substitutes the found char with whats actually on disk.


I have no idea how this is happening from what I am looking at, to be honest. What I see can be broken up into 3 steps:

path = re.sub(...path...)
results_list = glob(path)
result = results_list[0]

So to me it just looks like a string is being passed to glob, where the last character before each slash is being wrapped in [x]. I don't know how that translates into glob behaving any differently and matching any of the characters case-insensitive. It would take something like [xX] for every character to do that.

If I take an existing path on dist like: /path/to/a/file.ext
and I do this:

    glob("/Pat[h]/T[o]/[a]/File.ex[t]")

it certainly doesn't match anything. But if I did this:

    glob("/[pP]ath/[tT]o/a/[fF]ile.ext")

then I get a match because it is matching character sets. 
I must be missing something, or maybe I don't understand the capabilties of glob.

I really wanted to understand how this is working as you describe.

Chad_Fox

unread,
Nov 7, 2016, 12:39:50 PM11/7/16
to Python Programming for Autodesk Maya
Hey Justin,

I wish I knew more to explain it, I also thought the regex shouldn't work this way. Here's a screen grab of it working in maya.

Justin Israel

unread,
Nov 7, 2016, 1:31:11 PM11/7/16
to Python Programming for Autodesk Maya

Oh you are always running this on windows? I thought you said it was meant to run on linux to fix paths? Then I assume it only works on Windows because Windows doesn't care about case when you glob anything and having at least any wild card or character sets in your string just causes the matching to happen.

Basically that code won't work on Linux or osx


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Chad Fox

unread,
Nov 7, 2016, 3:22:00 PM11/7/16
to Python Programming for Autodesk Maya
Ah, I'm sorry that wasn't clear!   Yeah we only work on windows, but have recently started sending renders to the cloud.. all linux so all fixes happen in advance of cloud submission.

Reply all
Reply to author
Forward
0 new messages