获取路径中文件的修改日期
问题描述:
我从输入文件中获取一些路径名。我想返回修改日期 在我从输入file.However得到的路径中的所有文件,我得到的错误是这样的:获取路径中文件的修改日期
Traceback (most recent call last):
File "C:/Users/Ozann/Desktop/odev334-2bdeneme.py", line 13, in <module>
print ("last modified: %s" % time.ctime(os.path.getmtime(e)))
File "C:\Program Files (x86)\Python 3.5\lib\genericpath.py", line 55, in getmtime
return os.stat(filename).st_mtime
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\Users\\Ozann\\workspace2\n'
代码:
import os, os.path, time, re
with open("soru2bTest.txt", "r") as ins:
array = []
for line in ins:
array.append(line)
for e in array:
m = re.match("^(.*/)?(?:$|(.+?)(?:(\.[^.]*$)|$))",e)
if m :
print(e)
print("true")
print ("last modified: %s" % time.ctime(os.path.getmtime(e)))
答
你的错误得到是因为'C:\\Users\\Ozann\\workspace2\n'
是Windows
中的非法路径。 '\'
是分隔符,它是文件或目录中的非法字符名称。你可以在Windows
here找到非法字符的所有信息。