Problem with os.chdir()

venutaurus539 at gmail.com venutaurus539 at gmail.com
Wed Mar 11 09:59:57 EDT 2009


On Mar 11, 6:41 pm, Tim Golden <m... at timgolden.me.uk> wrote:
> venutaurus... at gmail.com wrote:
> > On Mar 11, 5:19 pm, Tim Golden <m... at timgolden.me.uk> wrote:
> >>> Here is my code snippet which you will be interested in:
> >> Indeed.
>
> >>> file = ur'\\?\C:\\TestDataSet\DeepPaths
> >>> \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
> >> And what happens if you remove that second double-backslash,
> >> the one between C: and TestDataSet?
>
> >> TJG
> > --------------------------------------------------------------------------- -------------
> > Even if I give the file path as below
>
> > file = ur'\\?\C:\TestDataSet\DeepPaths
> > \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
>
> > I am still getting the exception:
>
> > 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\\'
>
> Well, the source for os.chdir under Windows uses the Win32
> SetCurrentDirectoryW API as expected. What is not expected
> is that the MS docs for that function:
>
>  http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx
>
> still seem to suggest that you can't exceed MAX_PATH (ie 260)
> characters. And indeed, attempting to do a mkdir at the command
> line of something longer than that will also fail.
>
> Hmmm.. maybe the usual advice for naming files \\?\... doesn't
> apply to directory paths?
>
> Do you have an already existing full pathname that long?
>
> TJG

Yes Sir,
      My application demands me to create deep paths of (1023) long.
I've cross checked it and the folder actually exists.




More information about the Python-list mailing list