Jump to content
Sign in to follow this  
roystony01

Vbs Delete Files / Loop Help

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...