Problem with os.chdir()

V

venutaurus539

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\

Can someone please help me in this..

Thank you,
Venu M
 
T

Tim Golden

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
 
V

venutaurus539

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\\'

Thanks in advance,
Venu Madhav.
 
T

Tim Golden

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
 
V

venutaurus539

(e-mail address removed) 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)
 
T

Tim Golden

Here is my code snippet which you will be interested in:

Indeed.
file = ur'\\?\C:\\TestDataSet\DeepPaths
\DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\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
 
V

venutaurus539

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\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\\'

Please help..
Thank you,
Venu M
 
T

Tim Golden

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\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
 
V

venutaurus539

--------------------------------------------------------------------------- -------------
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.
 
T

Tim Golden

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.


Well, a little bit of experimentation shows that you can
*create* paths this deep (say, with os.mkdir). But you
can't actually set the current directory to it. So the
next question is: do you actually need to be *in* that
directory, rather than simply to reference it?

In other words, you can do this (assuming you have a c:\temp):

<code>
import os
for i in range (1, 15):
os.mkdir (ur"\\?\c:\temp\%s" % "\\".join (100 * "c" for j in range (i)))

</code>

But you can't then os.chdir to it. You're hitting the limits of
the OS. Try accessing files directly within the structure
you're using. (ie without chdir-ing there first).

TJG
 
V

venutaurus539

(e-mail address removed) 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.

Well, a little bit of experimentation shows that you can
*create* paths this deep (say, with os.mkdir). But you
can't actually set the current directory to it. So the
next question is: do you actually need to be *in* that
directory, rather than simply to reference it?

In other words, you can do this (assuming you have a c:\temp):

<code>
import os
for i in range (1, 15):
  os.mkdir (ur"\\?\c:\temp\%s" % "\\".join (100 * "c" for j in range (i)))

</code>

But you can't then os.chdir to it. You're hitting the limits of
the OS. Try accessing files directly within the structure
you're using. (ie without chdir-ing there first).

TJG

Sir,
My application has to rename a file in that folder.For that I had
to do a os.chdir() to that folder. Otherwise if I do a os.rename
(deeppath\file1,file2), it is creating a new file in the current
working directory with the new name and leaving the original file as
it is which is not intended :-(. So, can you suggest me any work
around for this?

Thank you
Venu.
 
T

Tim Golden

(e-mail address removed) 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.
Well, a little bit of experimentation shows that you can
*create* paths this deep (say, with os.mkdir). But you
can't actually set the current directory to it. So the
next question is: do you actually need to be *in* that
directory, rather than simply to reference it?

In other words, you can do this (assuming you have a c:\temp):

<code>
import os
for i in range (1, 15):
os.mkdir (ur"\\?\c:\temp\%s" % "\\".join (100 * "c" for j in range (i)))

</code>

But you can't then os.chdir to it. You're hitting the limits of
the OS. Try accessing files directly within the structure
you're using. (ie without chdir-ing there first).

TJG

Sir,
My application has to rename a file in that folder.For that I had
to do a os.chdir() to that folder. Otherwise if I do a os.rename
(deeppath\file1,file2), it is creating a new file in the current
working directory with the new name and leaving the original file as
it is which is not intended :-(. So, can you suggest me any work
around for this?

Jus
t rename from and to with a full pathname (using the \\?\ bit):

os.rename (ur"\\?\c:\long\path\to\file.txt", ur"\\?\c:\long\path\to\newfile.txt")

TJG
 
G

Gabriel Genellina

En Wed, 11 Mar 2009 11:59:57 -0200, (e-mail address removed)
My application demands me to create deep paths of (1023) long.
I've cross checked it and the folder actually exists.

As TJG said, it appears that you can create such deep path, and create and
use files inside, but you can't chdir into it:

py> cien = '0123456789'*10
py> path = ur"\\?\c:\%s\%s\%s\%s\%s\%s\%s\%s\%s\%s\%s\%s" % ((cien,)*12)
py> len(path)
1218
py> os.mkdir(path) # after creating all intermediate directories
py> fn = os.path.join(path, 'x.txt')
py> f = open(fn, "w")
py> f.write("hello")
py> f.close()
py> open(fn).read()
'hello'
py> os.chdir(path)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
WindowsError: [Error 123] El nombre de archivo, directorio o etiqueta del
volume
n no es vßlido:
u'\\\\?\\c:\\012345678901234567890123456789012345678901234567890..."

So your application should always use absolute paths.
 
H

Hendrik van Rooyen

Tim Golden said:
Well, a little bit of experimentation shows that you can
*create* paths this deep (say, with os.mkdir). But you
can't actually set the current directory to it. So the

Is this also true if you try to go there by a succession
of shorter hops of the ./next_level kind?

- Hendrik
 
T

Tim Golden

Hendrik said:
Is this also true if you try to go there by a succession
of shorter hops of the ./next_level kind?

- Hendrik


Yep. Seems to be. You reach a certain point and presumably
the internal "this is where I am" buffer runs out of oomph.

TJG
 
V

van Asselt

Hello,

In order to prevent this type of problems, I alway do the following:

import path

path = something
path = os.path.normpath(path)
os.chdir(path)

This prevents a lot of problems for me.

Regards,
Henk

Tim Golden said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top