2012-08-29 22 views
-4

我在一個python腳本中使用你的ftputil來獲取目錄中文件的最後修改/創建日期,我幾乎沒有問題,並想知道你是否可以提供幫助。我在一個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 

上面的列表不產生輸出

+1

誰是「你的」這裏指的是?同樣,從代碼中可以看出,如果'files'或'recursive'是空的,或者每個文件的'isfile'檢查都失敗了,你就不會輸出。嘗試在循環之前添加一個「打印文件」和「打印遞歸」。 – Daenyth

+0

遞歸= host.walk(目錄,自上而下=真,的onerror =無) 用於遞歸根,顯示目錄,文件: 進行名稱在文件: #mctime = host.stat(名)以上.mtime 打印名 – Echo

+0

產生一個遞歸的文件列表,文件包含一些東西 – Echo

回答

1

你已經把name引號。所以Python會一直在檢查字面文件名「name」,這大概不存在。您的意思是:

 if host.path.isfile(name): 
     mtime1 = host.stat(name) 
     mtime2 = host.stat(name).mtime 
相關問題