Command to delete all files in a directory?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
thepenguin99
Newbie
Posts: 8
Joined: Thu Jun 07, 2007 10:45 pm

Command to delete all files in a directory?

Post by thepenguin99 » Sat Jun 09, 2007 10:24 pm

Is there a command to delete all files in a directory? I don't want to delete the directory itself just everything in it. I am currently deleting the directory then recreating it but am looking for a better way.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Jun 10, 2007 1:57 am

Use the DOS command DEL with wildcards

Code: Select all

LET>RP_WAIT=1
Run Program>C:\command.com /c  DEL Drive:\Folder\*.*
...
Do More Stuff


-----------------------
Note - this is an edited sample. The original first line was in error as pointed out by JRL in a subsequent posting. The current posting is correct.
Last edited by Bob Hansen on Mon Jun 11, 2007 6:33 pm, edited 3 times in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

thepenguin99
Newbie
Posts: 8
Joined: Thu Jun 07, 2007 10:45 pm

Post by thepenguin99 » Mon Jun 11, 2007 1:48 am

Bob Hansen wrote:Use the DOS command DEL with wildcards


WAIT_RP=1
Run Program>C:\command.com /c DEL Drive:\Folder\*.*
Do More Stuff
What does wait_rp=1 do? I know most commands in the macro seem to change color when you type them in but this one remains black. Also the command doesn't work for me. Dos box comes up with specified command search bad. To many parameters. I think I am going to stick with just deleting and recreating since that works and doesn't seem to have any adverse effects. I would still like to know what wait_rp=1 does though =).

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jun 11, 2007 4:57 am

What Bob meant is Let>RP_WAIT=1 and what it does is tell the program to pause until the Run Program> line has completed.

See help for Run Program>

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

This will work

Post by Aaron » Mon Jun 11, 2007 6:15 am

If you have a SubFolder in your Directory it will not delete the SubFolder or the contents of the subfolder, but it will do what you asked for

Code: Select all

Label>StartLookingForNewFile

Wait>1

let>files=0

let>FN=0

GetFileList>C:\testing\*.*,files

Separate>files,;,file_names

Repeat>FN

Let>FN=FN+1

StringReplace>file_names_%FN%,C:\testing\,,file_name

       Label>LoopTillNameCount

IfFileExists>C:\testing\%file_name%,DeleteTheFile,NextLine

SRT>DeleteTheFile
DeleteFile>C:\testing\%file_name%
END>DeleteTheFile

Label>NextLine

Until>FN,file_names_count

Label>END
Hope this helps
Aaron

thepenguin99
Newbie
Posts: 8
Joined: Thu Jun 07, 2007 10:45 pm

Post by thepenguin99 » Mon Jun 11, 2007 6:35 am

Thx guys, got it.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Jun 11, 2007 3:13 pm

Thanks JRL for catching that syntax error.

I have modified my original posting.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts