I am using windows XP and need to write a DOS batch (.bat) file that will delete old files from a directory. This will run on a schedule and will not require human interaction to input any data. My problem is, I am not good at writing batch files. I can do the basic 101 type stuff, but finding dates and doing date comparison is beyond me.
Software/Hardware used:
Windows XP
ASKED:
October 20, 2009 3:05 PM
UPDATED:
April 4, 2012 7:28 AM
Click on the forfiles link in the answer above. You will need to download the utility.
Ok, I had overlooked the link and did not realize I had to do a download.
Thank you Troy and Labnuke99.
Hi,
I am trying to delete folders which are 3 days old. Folder size is more than 400MB. There are around 6-7 folders in this location. But the script i tried is deleting 1-2 folders.
I have used the below code in my VBS file.
strFolderPath = “C:TestBuilds” ‘Folder Path
strLogFolderPath=”C:TestBuildsLogs”
NumberOfDays = 3 ‘Anything older than this many days will be removed
On Error Resume Next
Dim fso,objFolder,objFile,objSubfolder,objLogFolder
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set objFolder = fso.GetFolder(strFolderPath)
Set objLogFolder = fso.GetFolder(strLogFolderPath)
‘DELETE all subfolders in Folder Path older than Number of days
For Each objSubfolder In objFolder.Subfolders
If objSubFolder.Name = “Logs” Then
‘ Set objSubFolder= Nothing
Else If DateDiff(“d”, objSubfolder.DateCreated,Now) > NumberOfDays Then
objSubfolder.Delete True
Wait 20
End If
End If
Next
‘Delete all the folders in Log folder
For Each objSubfolder In objLogFolder.Subfolders
If DateDiff(“d”, objSubfolder.DateCreated,Now) > NumberOfDays*5 Then
objSubfolder.Delete True
End If
Next
Set fso=Nothing
Set objFolder=Nothing
Set objLogFolder=Nothing
Set objSubfolder=Nothing
Can anyone suggest me on this.
- Durga Prasad