2015-11-01 71 views
0

我從輸入文件中獲取一些路徑名。我想返回修改日期 在我從輸入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))) 

回答

0

你的錯誤得到是因爲'C:\\Users\\Ozann\\workspace2\n'Windows中的非法路徑。 '\'是分隔符,它是文件或目錄中的非法字符名稱。你可以在Windowshere找到非法字符的所有信息。

相關問題