Hi,
I need a batch file to delete all PDF files in a folder and it's subfolders. I will be giving the folder path and number of old days to delete as static values..
Please it's very urgent. Also I have a VBScript file which works fine for the same.
Thanks
Manoj
I need a batch file to delete all PDF files in a folder and it's subfolders. I will be giving the folder path and number of old days to delete as static values..
Please it's very urgent. Also I have a VBScript file which works fine for the same.
Code:
Option Explicit
Dim FSO, WshShell, Then_Date, WSHShellENV, TempFolder, Recycled ' variables needed for main program(local scope)
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject") ' a new object to gain access to a computer's file system
Set WshShell = WScript.CreateObject("WScript.Shell") ' an object in type specified
Set WSHShellENV = WSHShell.Environment("PROCESS")
Set drv = FSO.GetDrive("D")
DoDir FSO.GetFolder("D:\TUSA\TUSA\CallCentre\CustomerReports")
DoDir FSO.GetFolder("D:\TUSA\Tusa\CustomerPortal\CustomerReports")
Then_Date = DateAdd("d", -5, Date) ' Files older than 5 days
WScript.Echo "Cleaned Files on " & Now & ". " & " Erased Files older than " & Then_Date
Sub DoDir(Folder)
Dim i, File, SubFolder, fstr, pos, last_mod ' variables needed for function
Dim Now_Date, Then_Date ' variable used for today's date
Now_Date = Date ' loads today's date into variable Now_Date
Then_Date = DateAdd("d",-5, Now_Date) ' Files older than 5 days
Dim Findstr(0) ' an array named Findstr with array element one
Findstr(0) = ".PDF" ' loads into array element 0, the .txt file extension
For Each File In Folder.Files ' For each file in folder.files
FStr = UCase(File.Path)
'WScript.Echo(FStr)
Pos = 0
for i = 0 to 0
if ((instr(FStr, Findstr(i)) > 0) And (File.DateCreated < Then_Date)) then
' check whether there exists a string inside FStr
' which has an extension of any of the elements of FindStr
'WScript.Echo(FStr) ' echos file string
File.delete ' if there is, simply delete it
Exit For
End if
Next
Next
For Each SubFolder in Folder.SubFolders
DoDir SubFolder
Next
End Sub
Sub ClearFolder(Folder)
Dim File, SubFolder
For each file in Folder.Files
File.delete(True)
next
'For Each SubFolder in Folder.SubFolders
' SubFolder.Delete(True)
'Next
End Sub
Manoj