480 pts.
 MS-DOS code to delete old Files
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

Answer Wiki:
Here's a <a href="http://blogs.technet.com/heyscriptingguy/archive/2004/11/04/how-can-i-delete-all-files-older-than-a-specified-date.aspx">VBScript for this activity</a>. I like using the <a href="http://winhlp.com/node/180">ForFiles utility</a> for this purpose. I found this batch file also. Be sure to test first in a test environment. <pre>@ECHO OFF IF "%DAY%" == "Monday" GOTO FIRST :SECOND forfiles /p d:FTPData /s /m *.* /d -2 /c "cmd /c del @file : date >= 1 day > NUL" GOTO END :FIRST forfiles /p d:FTPData /s /m *.* /d -4 /c "cmd /c del @file : date >= 3 days > NUL" GOTO END :END</pre> ________________________________________________________________________________ Thank you for your response. I ran the batch file at the DOS prompt and the "forfiles" command is not recognize . I received the below error message; 'forfiles' is not recognized as an internal or external command,operable program or batch file.
Last Wiki Answer Submitted:  October 20, 2009  5:34 pm  by  Labnuke99   32,645 pts.
All Answer Wiki Contributors:  Labnuke99   32,645 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Click on the forfiles link in the answer above. You will need to download the utility.

 0 pts.

 

Ok, I had overlooked the link and did not realize I had to do a download.

Thank you Troy and Labnuke99.

 480 pts.

 

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

 10 pts.