Hi all,
On Windows, it's very common to have a string of long directories in the
pathname for files, like "C:\Documents and Settings\My Long User Name\My
Documents\My Long Subdirectory Name\...". For a wxPython application I'm
working on, this has actually caused me to run into what appears to be
Python's pathname length limit for opening files. (247 chars on Win) Yes,
I can hear people saying "yipes!" but this stuff does happen sometimes on
Windows. :-)
My first inclination was to use win32api.GetShortPathName(mypath), which
worked fine until I had an unicode pathname with non-ascii characters in
it. Those give me the 'oridnal not in
range' errors performing an ascii encode, meaning that GetShortPathName
doesn't handle unicode objects. The problem is that I'm working with
Unicode filenames that contain characters that are not only non-ascii
characters, but characters not in the current locale's character set as
well. So I can't just 'down convert' from a unicode object to a string
object in the current character set without corrupting the filename.
Looking at the pyWin32 sources, it does look like only the ASCII version
of this function exists, which suggests that for now this route is a
dead-end.
The only other solution I could think of is to call
os.chdir(long_pathname) and open the file using a filename relative to
long_pathname instead of an absolute path. But I was wondering if there
was another solution, preferably one that doesn't require me to muck with
the current directory, and I was also wondering if there was a simple way
to get one or both of the above limitations removed. :-)
Thanks in advance for any help,
Kevin 3 2447
Kevin Ollivier: On Windows, it's very common to have a string of long directories in the pathname for files, like "C:\Documents and Settings\My Long User Name\My Documents\My Long Subdirectory Name\...". For a wxPython application I'm working on, this has actually caused me to run into what appears to be Python's pathname length limit for opening files. (247 chars on Win) Yes, I can hear people saying "yipes!" but this stuff does happen sometimes on Windows. :-)
The Win32 API restricts path arguments to 260 characters. Longer
paths can be passed to wide character functions by using a "\\?" prefix. http://msdn.microsoft.com/library/de...ing_a_file.asp
This may work from Python although I haven't tested it.
My first inclination was to use win32api.GetShortPathName(mypath), ... Looking at the pyWin32 sources, it does look like only the ASCII version of this function exists, which suggests that for now this route is a dead-end.
All APIs can be accessed through ctypes.
Neil
On Sat, 27 Aug 2005 23:30:46 +0000, Neil Hodgson wrote: Kevin Ollivier:
On Windows, it's very common to have a string of long directories in the pathname for files, like "C:\Documents and Settings\My Long User Name\My Documents\My Long Subdirectory Name\...". For a wxPython application I'm working on, this has actually caused me to run into what appears to be Python's pathname length limit for opening files. (247 chars on Win) Yes, I can hear people saying "yipes!" but this stuff does happen sometimes on Windows. :-) The Win32 API restricts path arguments to 260 characters. Longer paths can be passed to wide character functions by using a "\\?" prefix. http://msdn.microsoft.com/library/de...ing_a_file.asp This may work from Python although I haven't tested it.
My first inclination was to use win32api.GetShortPathName(mypath), ... Looking at the pyWin32 sources, it does look like only the ASCII version of this function exists, which suggests that for now this route is a dead-end.
All APIs can be accessed through ctypes.
Thanks for the tips! I had heard of ctypes but it never crossed my mind it
was for accessing functions from shared libraries. :-) I'll try both of
your tips out, and one of them should resolve the problem.
Kevin
Neil
Hi !
You are true.
But, more, don't believe : for use with CD-Rom/DVD, a path cannot to have
more than 64 caracteres.
@-salutations
Michel Claveau This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sebastien.hugues |
last post by:
Hi
I would like to retrieve the application data directory path of the
logged user on
windows XP. To achieve this goal i use the environment variable
APPDATA.
The logged user has this name:...
|
by: Edward K. Ream |
last post by:
Am I reading pep 277 correctly? On Windows NT/XP, should filenames always
be converted to Unicode using the mbcs encoding? For example,
myFile = unicode(__file__, "mbcs", "strict")
This...
|
by: Gerson Kurz |
last post by:
AAAAAAAARG I hate the way python handles unicode. Here is a nice
problem for y'all to enjoy: say you have a variable thats unicode
directory = u"c:\temp"
Its unicode not because you want it...
|
by: Michael Kearns |
last post by:
I've been using python to write a simple 'launcher' for one of our Java
applications for quite a while now. I recently updated it to use python
2.4, and all seemed well.
Today, one of my...
|
by: IdeaMan |
last post by:
Windows 2000
Access 97
I am working on an issue tracking DB, where I need to link (not attach
due to size)screen prints of various system errors.
I have created a public folder on a network...
|
by: Chris Paul |
last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows.
I've set this up countless times on BSD (piece of cake) but I'm trying
to do this on Windows now so that my developer can work...
|
by: Sergey |
last post by:
Hello.
I try to open file with pathname length 282 bytes:
E:\files\..................\something.dat
On MSDN...
|
by: Edward K. Ream |
last post by:
Hi. Presumably this is a easy question, but anyone who understands the sax
docs thinks completely differently than I do :-)
Following the usual cookbook examples, my app parses an open file...
|
by: Donn Ingle |
last post by:
Hello,
I hope someone can illuminate this situation for me.
Here's the nutshell:
1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale.
2. If this returns "C" or anything...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |