Filename too long error

M

Moqtar

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top