file names longer than MAX_PATH under Windows 2003
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Tue Feb 14 07:09:43 EST 2006
On Tue, 14 Feb 2006 22:43:50 +1100, Steven D'Aprano wrote:
> On Tue, 14 Feb 2006 14:29:44 +0300, Sergey wrote:
>
>> Hello.
>>
>> I try to open file with pathname length 282 bytes:
>> E:\files\..................\something.dat
>>
>> On MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp) described method to access
>> files with path length
>> up to 32000 bytes: just add prefix \\?\ to file name.
>> But when I try to pass prefixed name to file(), I get the same result as when I don't add the prefix: file not found. May be Python
>> just doesn't support long unicode filenames?
>> Is there way to open such files?
>
> Backslashes have special meaning to Python and need to be escaped. If you
> do this:
>
> f = file("E:\files\...\something.dat", "r")
>
> Python's string escape rules means you are actually trying to open the
> file "E:files...something.dat" which doesn't exist.
[slaps head]
I seem to be a bit confused about string escaping rules. Only some
backslashes have special meaning, the rest remain in the string.
Sergey, you said UNICODE file names. Not just ordinary strings.
Are you passing a unicode object to the function?
f = file(u"E:\\files\\...\\something.dat", "r")
--
Steven.
More information about the Python-list
mailing list