[-AI-] 移除舊資料夾

作者: GodIsland (搞不定嗎用C4就對了)   2016-09-30 14:31:35
在官網論壇看到的,還算簡單、稍微修改一下也可以用在檔案上
https://www.autoitscript.com/forum/topic/141837-script-to-remove-folders-
older-than-x-days/?do=findComment&comment=998117
#include <Array.au3>
#include <File.au3>
#include <Date.au3>
; put the root in a variable
$sRoot = "C:Test"
; Retrieve a list of all the folders in $sRoot, and store that list as an
array in $aList
Global $aList = _FileListToArray($sRoot, "*", 2) ; _FileListToArray("path" [,
"Filter" [, Flag]])
; Look at what _FileListToArray() puts into $aList
; You can delete the below line after seeing the output for the first time
_ArrayDisplay($aList)
; This is a loop that runs from 1 to the number of items listed in the first
element of the returned array
For $i = 1 To $aList[0]
; For each folder, get the modified date/time and store its individual
parts in array $aDate
$aDate = FileGetTime($sRoot & $aList[$i], 0, 0) ; FileGetTime("filename"
[, option [, format]])
; Look at what FileGetTime() puts into $aDate
; You can delete the below line after seeing the output for the first time
_ArrayDisplay($aDate)
; Build the properly formatted date string for _DateDiff()'s needs
$sDate = $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2] ;0 index stores
the year, 1 index stores month, 2 index stores day
; Look at what we made into $sDate
; You can delete the below line after seeing the output for the first time
msgbox(0,"Check Output", $sDate)
; Use _DateDiff() to see if the difference is greater than 3 days, and if
it's true, then delete the folder and all its subfolders
If _DateDiff("D", $sDate, _NowCalcDate()) > 3 Then DirRemove($sRoot &
$aList[$i], 1)
Next

Links booklink

Contact Us: admin [ a t ] ucptt.com