shorten path to files

Tim Golden mail at
Fri Jun 27 15:59:38 CEST 2008

> On 2008-06-27, cesco <fd.calabrese at> wrote:
>> Hi,
>> I need to retrieve the content of some files which are placed on a
>> network drive so in order to open them I need the full path to the
>> file.
>> Unfortunately some times the path is longer than 256 characters and in
>> Windows such a path is too long with the result that the file is not
>> found (though it is there).
>> Is there any way around this?

It's not clear from your description whether this applies, but there is
an API to obtain the short version of a Windows path:

(NB this is obviously the pywin32 project; I'm simply hosting a copy
of the docs).

Also, on more recent versions of the NT family, you can map drive
letters to deep paths, you can do something like this:

NET USE * \\server\share\path1\path2\path3\path4

and then do things with x:\path5\path6\ etc.

And you may find that passing a version of the filename
as in the example below will bypass the limit anyway. Note that
this uses the \\?\ prefix.

contents = open (ur"\\?\c:\some\really\long\path").read ()



More information about the Python-list mailing list