Jump to content

Vbs Delete Files / Loop Help


roystony01

Recommended Posts

Hi All, I have this script to delete files with a certain name older than x days. The script works ok, except that it wont run through the 7 file names consecutively. Currently if I run the script, it will delete the file beginning with ARBDWeek1. Then if I run it again, it will delete the older files for ARBEWeek2 etc. I need to add some script so that it will search for all the files listed so I can run a batch file to execute in the future Thanks On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") olddate = DateAdd("d", -3, date) WScript.StdOut.WriteLine("Today is " & Date & vbCrLf)WScript.StdOut.WriteLine("Deleting files unaccessed since " & olddate)WScript.StdOut.WriteLine(" ") WScript.stdout.writeline("Connecting to FileShare ")Set folder = fso.GetFolder(\\server\folder) ' Get the folderWScript.StdOut.Writeline("Getting a List of the Files")Set fc = folder.FilesFor Each f1 in fc If f1.DateLastModified < olddate And Left(f1.name,9) = "ARBDWeek1" Then WScript.StdOut.WriteLine("Removing: " & f1.DateLastModified & vbtab & f1.name) fso.deletefile(f1) End IfnextFor Each f1 in fc If f1.DateLastModified < olddate And Left(f1.name,9) = "ARBDWeek2" Then WScript.StdOut.WriteLine("Removing: " & f1.DateLastModified & vbtab & f1.name) fso.deletefile(f1) End IfnextFor Each f1 in fc If f1.DateLastModified < olddate And Left(f1.name,9) = "ARBDWeek3" Then WScript.StdOut.WriteLine("Removing: " & f1.DateLastModified & vbtab & f1.name) fso.deletefile(f1) End IfnextFor Each f1 in fc If f1.DateLastModified < olddate And Left(f1.name,9) = "ARBDWeek4" Then WScript.StdOut.WriteLine("Removing: " & f1.DateLastModified & vbtab & f1.name) fso.deletefile(f1) End IfnextFor Each f1 in fc If f1.DateLastModified < olddate And Left(f1.name,10) = "ARBDWeek4g" Then WScript.StdOut.WriteLine("Removing: " & f1.DateLastModified & vbtab & f1.name) fso.deletefile(f1) End IfnextFor Each f1 in fc If f1.DateLastModified < olddate And Left(f1.name,14) = "WorkstackTotal" Then WScript.StdOut.WriteLine("Removing: " & f1.DateLastModified & vbtab & f1.name) fso.deletefile(f1) End IfNextFor Each f1 in fc If f1.DateLastModified < olddate And Left(f1.name,10) = "FailedARBD" Then WScript.StdOut.WriteLine("Removing: " & f1.DateLastModified & vbtab & f1.name) fso.deletefile(f1) End Ifnext

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...