Hi all
I have been trying some VB script to delete old files in folder ("sszz") and its sub folder and creates a log file with deleted files information.
Now i want to skip one sub folder name it "samm"
So any modifications to the below code
Thanks
-----------------------------------------------------------------------------------
OPTION EXPLICIT
DIM strExtensionsToDelete,strFolder,count
DIM objFSO, MaxAge, IncludeSubFolders,strLOG,strMSG,sz,Suffix,TotalSize
Const cLog = "samad.log"
strFolder = "C:\sszz" 'Folder path
includeSubfolders = true
strExtensionsToDelete = ".txt,.xml" 'Format to delete
maxAge = 10 'no of days
count=0
sz=0
strMSG=" " & strExtensionsToDelete & " Files Deleted under "& strFolder
set objFSO = createobject("Scripting.FileSystemObject")
DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders
sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders)
DIM objFolder, objSubFolder, objFile
DIM strExt
set objFolder = objFSO.GetFolder(strDirectory)
for each objFile in objFolder.Files
for each strExt in SPLIT(UCASE(strExtensionsToDelete),",")
if Instr(1,UCASE(objFile.Path),strExt) > 0 then
'if RIGHT(UCASE(objFile.Path),LEN(strExt)+1)= "." & strExt then
IF objFile.DateLastModified < (Now - MaxAge) THEN
count=count+1
sz = sz + objFile.size
strLOG = strLOG & objFile & vbCrlf
objFile.Delete
exit for
End if
End if
next
next
if includeSubFolders = true then ' Recursive delete
for each objSubFolder in objFolder.SubFolders
DeleteFiles objSubFolder.Path,strExtensionsToDelete,maxAge, includeSubFolders
next
end if
end sub
Suffix = " Bytes"
If SZ >= 1024 Then suffix = " KB"
If SZ >= 1048576 Then suffix = " MB"
If SZ >= 1073741824 Then suffix = " GB"
If SZ >= 1099511627776 Then suffix = " TB"
Select Case Suffix
Case " KB" SZ = Round(SZ / 1024, 2)
Case " MB" SZ = Round(SZ / 1048576, 2)
Case " GB" SZ = Round(SZ / 1073741824, 2)
Case " TB" SZ = Round(SZ / 1099511627776, 2)
End Select
TotalSize = SZ & Suffix
objFSO.openTextFile(cLog,8,True,0).write("==================================================================="&vbCrLf)
objFSO.openTextFile(cLog,8,True,0).write("Date: " &date()&" "&"Time: "&Time() &vbCrLf)
objFSO.openTextFile(cLog,8,True,0).write("Total Size Deleted Today: " &TotalSize &vbCrLf& "Files Deleted Today: " &Count &vbCrLf)
if Len(strLOG) > 0 then
objFSO.openTextFile(cLog,8,True,0).write(strLOG)
else
objFSO.openTextFile(cLog,8,True,0).write("No Files to Delete"&vbCrLf)
end if
objFSO.openTextFile(cLog,8,
-------------------------------------------------------------------------------------------------------------------------------------------