jmohan0302
asked on
Need a script
Hi,
I need a script to identify what are the folders that are 7 days old in a particular path and to delete those folders automatically. The script should look only for folders and not for files. Thanks
I need a script to identify what are the folders that are 7 days old in a particular path and to delete those folders automatically. The script should look only for folders and not for files. Thanks
... sorry only saw now you asking about vb
ASKER
Not a problem I need any thing that fulfills my work. Even a command or a script any thing
This should be close, adjust the constants at the top as needed. Right now the actual delete is commented out, and it will just display the folders it thinks should be deleted. This is for testing, if it works right uncomment out the delete. Also, it is checking the date the folder was created currently, not last modified, since you didn't specify I wasn't sure so started with this.
Const conBaseDir = "C:\EE\Temp"
Const conDelAge = 7
' Create file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
' Call recursive routine to clean out old folders
CleanFolder objFSO.GetFolder(conBaseDir), conDelAge
' Release file system object
Set objFSO = Nothing
' Recursive subroutine to remove old subfolders
Sub CleanFolder(objFolder, intAge)
' See if this folders subfolders are old enough to delete.
For Each objSubFolder In objFolder.SubFolders
If DateDiff("d", objSubFolder.DateCreated, Now) >= intAge Then
' objSubFolder.Delete
Wscript.Echo "Deleted Folder: [" & objSubFolder.Path & "], Age: [" & DateDiff("d", objSubFolder.DateCreated, Now) & "]"
Else
CleanFolder objSubFolder, intAge
End If
Next
End Sub
~bp
ASKER
Hi Billprew, Thanks for your reply. Yet I didnt check. I will check and let you know the output. I just want to know that it has to delete all the folders that is 7 days old. Thanks again
ASKER
Hi Gavincr001,
Please let me know from where you got these kind of commands. I just want to create these kinds of commands on own. Any help from your end will be greatfull. Thanks
Please let me know from where you got these kind of commands. I just want to create these kinds of commands on own. Any help from your end will be greatfull. Thanks
ForFiles is an add on utility for Windows from Microsoft. It was released in some of the Resource Kits and now is also part of Windows 7. Further info can be found at:
http://technet.microsoft.com/en-us/library/cc753551%28WS.10%29.aspx
http://www.petri.co.il/download_free_reskit_tools.htm
~bp
http://technet.microsoft.com/en-us/library/cc753551%28WS.10%29.aspx
http://www.petri.co.il/download_free_reskit_tools.htm
~bp
ASKER
Hi All,
The below forfiles command is working fine in Win7,WIn2003 and WIn2008:
forfiles /p "e:\shilpa" /c "cmd /c if @isdir==TRUE RMDIR /S /Q @path" /d -20
But it is not working in win2000.
Need help to use the forfiles command in 2000 to delete the folders in a path which is 7 days old.
Thanks
The below forfiles command is working fine in Win7,WIn2003 and WIn2008:
forfiles /p "e:\shilpa" /c "cmd /c if @isdir==TRUE RMDIR /S /Q @path" /d -20
But it is not working in win2000.
Need help to use the forfiles command in 2000 to delete the folders in a path which is 7 days old.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This example, removes directories older than 20 days in c:\temp.
forfiles /p "c:\temp" /c "cmd /c if @isdir==TRUE RMDIR /S /Q @path" /d -20