hcour Posted June 4, 2008 Report Share Posted June 4, 2008 Is it possible to write a macro that would delete all files in a specific folder that were X number of days old? If so, could someone get me started on how I'd do that? Thanks much, Harold Quote Link to comment Share on other sites More sharing options...
rberq Posted June 4, 2008 Report Share Posted June 4, 2008 The brute-force method comes to mind. Set up a macro to do the following: First run the DOS dir command sending output to a text file: Launch c:\windows\system32\cmd.exe and pass it parameter /C dir c:\targetdir > c:\temp\dirlist.txt Then open c:\temp\dirlist.txt with Notepad: Launch c:\windows\system32\cmd.exe and pass it parameter /C c:\windows\system32\notepad.exe c:\temp\dirlist.txt Text Type CTRLD - END - CTLRU to take you to the end of the file. Text Type a string of nines or ampersands or something that you can recognize as a stopping point in the REPEAT loop below. Text Type CTRLD - HOME - CTRLU to take you back to the beginning of the file. Now process each line of the file; REPEAT START Highlight and copy file date parts into clipboard and from there into three Txx text variables (month day year) Check whether your Txx variables contain your end-of-file marker (ampersands or whatever you inserted above) -- if so, exit from the REPEAT loop) Compare the month day year variables to your purge date If date is within the purge range, ARROW RIGHT to where the file name is displayed, highlight and copy name into the clipboard and from there into a text variable, construct a DOS delete command in a text variable Txx, launch the delete command: Launch c:\windows\system32\cmd.exe and pass it parameter /C del %Txx% Text Type HOME - ARROW DOWN to get to the next line in your file REPEAT Quote Link to comment Share on other sites More sharing options...
hcour Posted June 5, 2008 Author Report Share Posted June 5, 2008 Thanks so much, rberq! Looks great. Harold Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.