Jump to content

Vbs Delete Files / Loop Help


roystony01
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...