刪除 n天前檔案的方法:Belvedere、Xdel與DelAge32

同事提出了一個需求:每天定期刪除10天前檔案的方法。我第一個想到的是以前介紹過的這個Belvedere: 檔案管理自動化工具,但另一個同事提出了更好的工具:xdel

xdel.exe是一個13KB的執行檔,由命令行執行,可以做一個批次檔再放到啟動資料夾裡每天定時執行。

xdel [-listonly] [-dirsonly|-filesonly] [-recurse] [-dolog]
     [-ctime TIME|-mtime TIME] [-debug] dir[pattern]

XDEL範例

刪除建檔日期5天前的c:\temp資料夾裡的*.log:

xdel -ctime Now-5d "c:\temp\*"

星號就是pattern,可惜我在Windows 7裡使用*.log時程式會當掉,用「*」,「任何字串*」則可將正常執行。

刪除異動日期10天前的檔案:

xdel -mtime Now-10d "c:\temp\*"
  • 加了-recurse則其下子目錄裡符合日期的檔案會一併刪除
  • -listonly:只顯示符合條件的檔案或資料夾,不會實際執行刪除的動作
  • -dirsonly:只刪除符合條件的資料夾
  • -filesonly:只刪除符合條件的檔案(預設選項)

完整說明看readme.txt就可以了。

XDEL資訊

DELAGE32

delage32.exe是另一個相同功能的程式,提供的選項更多,且可指定*.log這樣的參數。

DelAge32 - ver. 2.3 (c) 2003-2008, Horst Schaeffer
Deletes or moves files (path with file pattern) by age (number of days)
Syntax:  DelAge32 filespec age [options]
Options:
  /created /accessed /modified (default) - file stamp used to evaluate age
  /includeRO - include read-only files
  /includeH  - include hidden files
  /includeS  - include system files
  /includeRHS -include read-only, hidden and system files
  /recurse   - include subdirectories
  /subonly   - /recurse excluding initial directory
  /rd        - remove empty subdirectories
  /move path - move files to specified path
  /preview   - list, but no action
  /quiet     - no output
  • 範例:刪20天前的*.log,且移除空的資料夾
delage32 e:\*.log 20 /rd

##

您可能也會有興趣的類似文章

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

4 個回應

  1. Takalang表示:

    不錯的工具軟體,看能否再增加參數,不刪除子資料夾底下檔案。

    • 簡睿表示:

      我後來都是用delage64, 預設不處理子目錄,加了 -recurse才會處理子目錄。

  2. 蔡小翰表示:

    http://www.horstmuc.de/win/delage-de.htm

    我是用DelAge32, Version 2.3 這套也不錯喔

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *