June 28, 2010 at 1:57 pm
Hi,
I am looking for a script (Preferable VB) connects to multiple servers and generate a list (not delete) of all the .Bak files older than 4 days.
Need to scan the root drives and the sub folders. Pretty much a newbie.. so any help would be much appreciated
Regards
Sandhya
June 28, 2010 at 2:22 pm
This function should find the matching files in a directory.
Public Function GetFiles(ByVal FileDir As String, ByVal FilePattern As String) As Long
' Process the matching files in FileDir
' Call as e.g. Filecount = GetFiles("C:\Temp", "*.bak")
Dim Files() As String = System.IO.Directory.GetFiles(MailingDir, FilePattern) ' Find any matching file in the directory
For Each File As String In Files
Dim Filename As String = System.IO.Path.GetFileNameWithoutExtension(File)
Dim Ext As String = System.IO.Path.GetExtension(File)
MsgBox(String.Format("Found file {0} with Name {1} and Ext {2}", File, Filename, Ext))
' Do stuff with the file
Next File
Return Files.Length ' Return number of files
End Function
You can check the file date with
FileDate = System.IO.File.GetLastWriteTime(File)
If you want to search through subdirectories, you'll need to use FileAttribute to test whether a directory content is a file or another directory.
June 28, 2010 at 3:27 pm
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply