Problem with os.chdir()

venutaurus539 at gmail.com venutaurus539 at gmail.com
Wed Mar 11 08:11:00 EDT 2009


On Mar 11, 5:02 pm, Tim Golden <m... at timgolden.me.uk> wrote:
> venutaurus... at gmail.com wrote:
> > On Mar 11, 11:08 am, Tim Golden <m... at timgolden.me.uk> wrote:
> >> venutaurus... at gmail.com wrote:
> >>> Hello all,
> >>>            I am writing a python script which has to access deep paths
> >>> then supported normally by the Windows OS (>255). So I am appending "\
> >>> \?\" to do so. But when I use the path in the above fashion with
> >>> os.chdir() it is unable to recognize my folder and throwing an error:
> >>> Traceback (most recent call last):
> >>>   File "C:\JPDump\test.py", line 31, in <module>
> >>>     renameStubs(file)
> >>>   File "C:\JPDump\test.py", line 15, in renameStubs
> >>>     os.chdir (path)
> >>> WindowsError: [Error 123] The filename, directory name, or volume
> >>> label syntax is incorrect: '\\?\\C:\\TestDataSet\
> >>> \Many_Files_10000_1KB_FIles\\001_0009_1000 FILES\\'
> >>> The value of my path variable is
> >>> \?\C:\TestDataSet\Many_Files_10000_1KB_FIles\001_0009_1000 FILES\
> >> There need to be two backslashes at the beginning:
>
> >> \\?\C:\TEST.....FILES\
>
> >> Note the double backslash before the question mark.
>
> >> TJG
>
> > I've another situation where os.chdir() function failed. Please find
> > the traceback pasted below:
> > Traceback (most recent call last):
> >   File "C:\JPDump\test.py", line 29, in <module>
> >     renameStubs(file)
> >   File "C:\JPDump\test.py", line 12, in renameStubs
> >     os.chdir (path)
> > WindowsError: [Error 206] The filename or extension is too long: '\\?\
> > \C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
> > \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
> > \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
> > \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
> > \DeepPathLevel15\\DeepPathLevel16\\'
>
> Try it as a unicode string:
>
> os.chdir (ur"\\?\c:\test...\deep...")
>
> TJG

Sorry.. even that failed:

Traceback (most recent call last):
  File "C:\JPDump\test.py", line 29, in <module>
    renameStubs(file)
  File "C:\JPDump\test.py", line 12, in renameStubs
    os.chdir (path)
WindowsError: [Error 206] The filename or extension is too long: u'\\\
\?\\C:\\\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\
\DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\
\DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\
\DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\
\DeepPathLevel15\\DeepPathLevel16\\'
---------------------------------------------------------------------------------------------------------------
Here is my code snippet which you will be interested in:

file = ur'\\?\C:\\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
def renameStubs(file):
    #e.write(u"\n"+strftime("%Y-%m-%d %H:%M:%S") +" we are in
renameStubs function \n")
    drive = file.split(":")[0]
    oldName = file.split("\\")[-1]
    path = file.rstrip(oldName)
    os.chdir (path)
    ............
renameStubs(file)



More information about the Python-list mailing list