Problem with os.chdir()

Tim Golden mail at
Wed Mar 11 14:41:30 CET 2009

venutaurus539 at wrote:
> On Mar 11, 5:19 pm, Tim Golden <m... at> 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\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt'
> I am still getting the exception:
> Traceback (most recent call last):
>   File "C:\JPDump\", line 29, in <module>
>     renameStubs(file)
>   File "C:\JPDump\", 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:

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?


More information about the Python-list mailing list