| 1. |
Solve : Check several locations in a .vbs script to delete files by date.? |
|
Answer» I found a script on the forums by Sidewinder to delete files by date for a specific location, the code is below and I would like to be able to specify different locations and have it loop through for each location. Either by looking at an external file or by adding something in the current script and listing out each location. Can anyone assist me with this? C:\delbydate.vbs(11, 4) Microsoft VBScript runtime error: Path not found I am assuming it is stating 11 line and 4th character in there is an issue? At that location is the following code. Code: [Select] Set k = fso.GetFolder(Fld)The error is reproducible by entering an invalid directory name in the external file. I added some code for the snippet to crash and burn if a directory from the external file is not found. Code: [Select]Const ForReading = 1 Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("c:\temp\input.txt", ForReading) 'point to correct file Do While f.AtEndOfStream <> True fs = f.ReadLine ShowFiles(fs) Loop f.Close Sub ShowFiles(Fld) If fso.FolderExists(fld) Then Set k = fso.GetFolder(Fld) Else WScript.Echo "Invalid Directory:",fld WScript.Quit End if Set s = k.SubFolders Set kf = k.Files For Each objFile In kf If fso.GetExtensionName(objFile) = "txt" then If objFile.DateCreated < date - 3 Then ' age factor is days WScript.Echo objFile & " " & objFile.DateCreated 'fso.DeleteFile objfile End If End if Next For Each SubFolder In s ShowFiles SubFolder Next End Sub But those directories work fine if I use them in the first script, why would that happen? The paths are UNC name btw not sure if that effects it differently in this version of the script.Your not giving us enough information. Did the last posted version of the script ISSUED an Invalid Directory message? Can you GIVE us an example of what is in the external file? This script has been tested with directories containing embedded spaces and UNC paths, with no problems. Are you STILL getting a VBScript error, or just no results at all? Keep in mind the script is filtering only txt extensions.That was it I was missing a letter in one of the paths, sorry about not giving as much detail. Looks like the script doesn't do anything once it runs into a bad path. Thanks so much for you assistance Sidewinder! |
|