Filename Too Long
Martin v. Loewis
martin at v.loewis.de
Fri Apr 5 13:51:13 EST 2002
rudi_sass at yahoo.com (Peter D) writes:
> I'm using windows and trying to call os.path.getmtime() after using
> os.path.walk... However, I'm choking with "[Errno 38] Filename too
> long" on paths with len > ~260
>
> Is there any way around this error?
Since you are asking for a work-around: cd into one of the more nested
directories when the path gets longer (os.chdir), and use relative
paths from then on.
If you want to study how to solve the problem: the relevant code
snippet is in Modules/posixmodule.c
/* the library call can blow up if the file name is too long! */
if (pathlen > MAX_PATH) {
PyMem_Free(pathfree);
errno = ENAMETOOLONG;
return posix_error();
}
There might be different ways to approach this:
- challenge the correctness of the comment:
- try to establish why the author of that code thought that the C
library could blow up
- analyse whether these arguments are still true with the current
compiler version
-or-
- prove the argument wrong by analysing the source code of the C
library
- then remove the constraint
-or-
- use different API to achieve the same effect without suffering from
the constraint.
I'm serious about these suggestions: users would appreciate if this
gets fixed somehow - apparently, the system allows longer file names,
and apparently, the system itself can deal with that quite well. This
can be only true if the system either doesn't use its C library, or if
the C library does not have this restriction.
HTH,
Martin
More information about the Python-list
mailing list