Jump to content

roystony01

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About roystony01

  • Rank
    Newbie
  1. 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
  2. Hi All, I am a beginner in writing VBS. I am trying to write a script that will copy a csv file that contains todays date, and move it to another folder, and also rename the file without the date. This is the script I have, there are no errors when I run the script, but nothing actually happens. i have been scratching my head for a few days now. Please note I have changed the folder paths, as these are sensitive and cant be shared publicly, but I am positive there are noe read write issues, and they are written correctly Any help, muchly appreciated. Roy Sub Copy_Files_Dates() Dim FSO Dim FromPath Dim ToPath Dim Fdate Dim FileInFromFolder DIM FName FromPath = ("C:\folder") ToPath = ("C:\folder") If Right(FromPath, 1) <> ("\") Then FromPath = FromPath & "\" End If If Right(ToPath, 1) <> "\" Then ToPath = ToPath & "\" End If FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(ToPath) = False Then MsgBox(ToPath & " doesn't exist") Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) FName = String(FileInFromFolder.Name) If Fdate >= int(now()) AND Left(FName,9) = ("ARBDWeek1") Then FileCopy FromPath & FName, ToPath & ("ARBDWeek1.csv") End If NextEnd Sub
×
×
  • Create New...