vendredi 10 avril 2015

Long paths in Python on Windows

I have a problem when programming in Python running under Windows. I need to work with file paths, that are longer than 256 or whatsathelimit characters. Now, I've read basically about two solutions:



  1. Use GetShortPathName from kernel32.dll and access the file in this way.


That is nice, but I cannot use it, since I need to use the paths in a way



shutil.rmtree(short_path)


where the short_path is a really short path (something like D:\tools\Eclipse) and the long paths appear in the directory itself (damn Eclipse plugins).



  1. Prepend "\\\\?\\" to the path


I haven't managed to make this work in any way. The attempt to do anything this way always result in error WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: <path here>


So my question is: How do I make the 2nd option work? I stress that I need to use it the same way as in the example in option #1.


OR


Is there any other way?


EDIT: I need the solution to work in Python 2.7


Aucun commentaire:

Enregistrer un commentaire