option explicit
dim fpath,fso,logfile,fwrite
fpath=inputbox ("輸入目標資料夾","檔案處理器")
logfile="logfile.txt"
set fso=createobject("scripting.filesystemobject")
Set fwrite=fso.opentextfile(logfile,8,true)
getfilename fpath
fwrite.close
Set fso=Nothing
MsgBox "命令執行完成!"
function getfilename(path)
dim file,folder,sfolder,fname,subfolder,Files
if not fso.folderexists(path) then
set fso=nothing
msgbox "目標資料夾不存在!"
exit function
end if
set folder=fso.getfolder(path)
set files=folder.files
for each file in Files
fwrite.writeline path&"\"&file.name
If file.DateLastModified < Now - 20 Then "判斷是否超過20天
fso.DeleteFile(file)
"Wscript.Echo file
End If
next
set subfolder=folder.subfolders
for each sfolder in subfolder
fwrite.writeline path&"\"&sfolder.name
If sfolder.DateCreated < Now - 20 Then "判斷是否超過20天
fso.deletefolder(sfolder)
end function
再開啟目標資料夾之後就沒有檔案了。
option explicit
dim fpath,fso,logfile,fwrite
fpath=inputbox ("輸入目標資料夾","檔案處理器")
logfile="logfile.txt"
set fso=createobject("scripting.filesystemobject")
Set fwrite=fso.opentextfile(logfile,8,true)
getfilename fpath
fwrite.close
Set fso=Nothing
MsgBox "命令執行完成!"
function getfilename(path)
dim file,folder,sfolder,fname,subfolder,Files
if not fso.folderexists(path) then
set fso=nothing
msgbox "目標資料夾不存在!"
exit function
end if
set folder=fso.getfolder(path)
set files=folder.files
for each file in Files
fwrite.writeline path&"\"&file.name
If file.DateLastModified < Now - 20 Then "判斷是否超過20天
fso.DeleteFile(file)
"Wscript.Echo file
End If
next
set subfolder=folder.subfolders
for each sfolder in subfolder
fwrite.writeline path&"\"&sfolder.name
If sfolder.DateCreated < Now - 20 Then "判斷是否超過20天
fso.deletefolder(sfolder)
"Wscript.Echo file
End If
next
end function
再開啟目標資料夾之後就沒有檔案了。