【问题标题】:get modificated dates of files in a path获取路径中文件的修改日期
【发布时间】:2016-02-01 12:24:47
【问题描述】:

我从输入文件中得到一些路径名。我想返回修改日期 对于我从输入文件获得的路径中的所有文件。但是,我收到如下错误:

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)))

【问题讨论】:

    标签: python regex file-io path directory


    【解决方案1】:

    您遇到的错误是因为'C:\\Users\\Ozann\\workspace2\n'Windows 中的非法路径。虽然'\' 是分隔符,但它是文件或目录name 中的非法字符。你可以在Windowshere找到所有关于非法字符的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 2016-12-09
      • 2015-02-19
      • 1970-01-01
      • 2019-02-26
      • 2012-12-06
      相关资源
      最近更新 更多