#這個程式是仿自linux下的tmpwatch,但只有簡單的功能 #希望對你有所幫助,這個程式是命令列的程式 #寫於2007/02/21 #tmpwatch 第一個變數是檔案超分鐘刪除,第二個變數是檔案所在的路徑,第三個變數是檔名(支援*) #command $cmdline第一個變數是命令列變數有幾個,第二個以後為命令內容 #例如: # tmpwatch 100h c:\windows\temp # 刪除所在目錄c:\windows\temp下所有距今超過100小時的檔案 # tmpwatch 100m c:\windows\temp *.xls # 刪除所在目錄c:\windows\temp下所有距現在超過100分鐘的檔案,且副檔名為xls #include #include #Include $arg=$cmdline[0] if $arg<2 then msgbox(1,"tmpwatch","所提供的參數不足"&@LF&"1.第一個參數為檔案日期和現在時間的差超過多少時間要被刪除(後加m(分鐘)或h(小時))"&@LF&"2.第二個參數目錄所在"&@LF&"3.第三個參數是檔名(支援*)") Else $diff=$cmdline[1] if stringright($diff,1)="h" or STRINGRIGHT($diff,1)="H" or stringright($diff,1)="m" or stringright($diff,1)="M" Then if stringright($diff,1)="h"or stringright($diff,1)="H" Then $diff=stringleft($diff,stringlen($diff)-1)*60 Else $diff=stringleft($diff,stringlen($diff)-1) EndIf Else msgbox(0,"tmpwatch","請在時間後加m(分),h(小時)") Exit EndIf $path=$cmdline[2] if $arg=3 Then $filefilter=$cmdline[3] EndIf if FileExists($path) Then if $arg=2 Then $FileList=_FileListToArray($path) Else $FileList=_filelisttoarray($path,$filefilter) EndIf _ArrayDelete( $FileList,0) $i=0 If (Not IsArray($FileList)) Then MsgBox (0,"訊息視窗","目錄"&$PATH&"檔案不存在 .",10) Exit Else FOR $element IN $FileList $element = $path &"\"& $element $t=FileGetTime($element) $y = $t[0] &"/"& $t[1] &"/"& $t[2] &" "&$t[3]&":"&$t[4]&":00" if compare_date($y,$diff)Then $I=$I+1 FileDelete ( $element ) Else EndIf NEXT msgbox(0,"","共計:" &$i &" 被刪除",5) EndIf Else msgbox(1,"訊息視窗","指定的路徑不存在"&$path) endif endif func compare_date ($v1,$v2) $retvar=0 if _DateDiff ( 'n', $V1,_NowCalc() )>$v2 Then $retvar=1 EndIf return $retvar EndFunc