-4

我在 python 脚本中使用你的 ftputil 来获取目录中文件的最后修改/创建日期,我遇到了一些问题,想知道你是否可以提供帮助。

      host.stat_cache.resize(200000)
 recursive = host.walk(directory, topdown=True, onerror=None)
  for root,dirs,files in recursive:
       for name in files:
            #mctime = host.stat(name).mtime
            print name

以上输出目录中所有文件的列表

      host.stat_cache.resize(200000)
 recursive = host.walk(directory, topdown=True, onerror=None)
 for root,dirs,files in recursive:
       for name in files:
          if host.path.isfile("name"):
             mtime1 = host.stat("name")
             mtime2 = host.stat("name").mtime
             #if crtime < now -30 * 86400:
             #print name + " Was Created " + " " + crtime + " " + mtime
             print name + " Was Created " + " " + " " + mtime1 + " " + mtime2

上面没有输出

4

1 回答 1

1

你已经加name了引号。因此 Python 将始终检查文字文件名“name”,它可能不存在。你的意思是:

      if host.path.isfile(name):
         mtime1 = host.stat(name)
         mtime2 = host.stat(name).mtime
于 2012-08-29T16:26:45.150 回答