Jump to content
Macro Express Forums

Macro to Delete Files?


hcour
 Share

Recommended Posts

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...