I am trying to list the names and sizes of all files in a directory but get an error when there are files in chinese, i am using Python 2.7 on windows 7
this is my code
import os
path = '\'
listing = os.listdir(path)
for infile in listing:
if infile.endswith(".csv"):
print infile + ";"+ str(os.path.getsize(path + infile))
this is the error I get
Traceback (most recent call last):
File "file_size.py", line 8, in <module>
print infile + ";"+ str(os.path.getsize(path + infile))
File "C:\Python27\lib\genericpath.py", line 49, in getsize
return os.stat(filename).st_size
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: '\DB?1333366331.436754.048342.csv'
C:\>python file_size.py
File "file_size.py", line 7
if infile.endswith(".csv"):
^
IndentationError: unindent does not match any outer indentation level
The name of the file that caused the error is DB表1333366331.436754.048342.csv
How can i avoid this problem?
thanks in advance