Filename too long error

Moqtar moqtar at gmail.com
Mon Dec 4 23:09:43 EST 2006


I am trying to walk a directory and print the file and its modified
time. When the path is longer then 259 characters i get an error
"Filename too long". I guess these is because windows limitation on
path length.

My code:

import os
import time

for root,dirs,files in os.walk(directory):
   	for file in files:
                fullpath=os.path.join(root,file)
                print fullpath
                print 'Length',len(fullpath)
                ModifiedTime=os.path.getmtime(fullpath)
                print ModifiedTime

Ouput Error:
D:\2\users\1111111111111111111111111111111111111111111111111111111111111111111111111111
\22222222222222222222222222222222222222222222222222
\33333333333333333333333333333333333333333333333333
\4444444444444444444444444444444444444444444444444
\5555555555555\1111111.txt
Length 265

Traceback (most recent call last):
  File "C:\Python24\hello.py", line 17, in -toplevel-
    ModifiedTime=os.path.getmtime(fullpath)
  File "C:\Python24\lib\ntpath.py", line 233, in getmtime
    return os.stat(filename).st_mtime
OSError: [Errno 38] Filename too long

Is there a way to find the modified time of long path?




More information about the Python-list mailing list