Hi,

I am using a scheduled task that runs every night to take backup of important files. This task creates a folder in the following format

Backup_DD_MM_YY

where DD_MM_YY denotes the date when the backup was taken.

Now everytime this scheduler runs I need to remove the older directory and create a new one with current date. In order to remove the directory I tried the following but it doesn't work. for %%A in (C:\Backup*) do rmdir /s /q %%A Can somebody please help

Recommended Answers

All 3 Replies

Hey There,

Unless it's a permissions issue (where you can't delete the folders as the user that runs the batch file) is it possible that you're trying this at the command line as proof-of-concept for the batch file.

If you're doing command line testing, although the variable MUST be %%A in your batch file, it has to be %A when run from the command line (why? I haven no idea ;)

c:\cygwin\tmp\test>dir
 Volume in drive C has no label.
 Volume Serial Number is F08F-D325

 Directory of c:\cygwin\tmp\test

12/16/2008  10:15 PM    <DIR>          .
12/16/2008  10:15 PM    <DIR>          ..
12/16/2008  10:15 PM    <DIR>          test1
               0 File(s)              0 bytes
               3 Dir(s)   4,743,143,424 bytes free

c:\cygwin\tmp\test>FOR /D %A IN (C:\cygwin\tmp\test\*) DO rmdir /s /q %A

c:\cygwin\tmp\test>rmdir /s /q C:\cygwin\tmp\test\test1

c:\cygwin\tmp\test>dir
 Volume in drive C has no label.
 Volume Serial Number is F08F-D325

 Directory of c:\cygwin\tmp\test

12/16/2008  10:16 PM    <DIR>          .
12/16/2008  10:16 PM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)   4,743,143,424 bytes free

c:\cygwin\tmp\test>

Best wishes,

Mike

commented: Simply awesome! +2

Hi Eggi,

Problem Solved.....Dude you are genius :). See you around

Cool... and thanks :)

Glad you're doing good!

, Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.