shorten path to files
Tim Golden
mail at timgolden.me.uk
Fri Jun 27 09:59:38 EDT 2008
> On 2008-06-27, cesco <fd.calabrese at gmail.com> 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:
http://timgolden.me.uk/pywin32-docs/win32api__GetShortPathName_meth.html
(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.
<code>
contents = open (ur"\\?\c:\some\really\long\path").read ()
</code>
TJG
More information about the Python-list
mailing list