HOW TO CLEAN A FOLDER CONTENT USING CMD

E

EziContact1

Hello all

can any one help?

I need to clean few folders using a batch file ..but I couldn't find a
way to delete subdirectories (Without deleting Root folder)

Eg:
if we have this tree:
C:\Folder1\folder2\files 1 2 3 etc
C:\Folder1\folder3\files 1 2 3 etc
C:\Folder1\folder4\folder5\files 1 2 3 etc
C:\Folder1\files 1 2 3 etc

I need to del (erase everything in "C:\Folder1" without deliting
folder1)

At the moment I use (RD "C:\Folder1" ~~ and MD "C:\Folder1")but it has
some side effects.

Thank you all for help...
 
M

Matthias Tacke

EziContact1 said:
Hello all

can any one help?

I need to clean few folders using a batch file ..but I couldn't find a
way to delete subdirectories (Without deleting Root folder)

Eg:
if we have this tree:
C:\Folder1\folder2\files 1 2 3 etc
C:\Folder1\folder3\files 1 2 3 etc
C:\Folder1\folder4\folder5\files 1 2 3 etc
C:\Folder1\files 1 2 3 etc

I need to del (erase everything in "C:\Folder1" without deliting
folder1)

At the moment I use (RD "C:\Folder1" ~~ and MD "C:\Folder1")but it has
some side effects.

Thank you all for help...
A week ago there was a similar question in alt.msdos.batch.nt ;-)
Read my answer:
http://groups.google.com/[email protected]
 
M

Mark V

In said:
Hello all

can any one help?

I need to clean few folders using a batch file ..but I couldn't
find a way to delete subdirectories (Without deleting Root
folder)

Eg:
if we have this tree:
C:\Folder1\folder2\files 1 2 3 etc
C:\Folder1\folder3\files 1 2 3 etc
C:\Folder1\folder4\folder5\files 1 2 3 etc
C:\Folder1\files 1 2 3 etc

I need to del (erase everything in "C:\Folder1" without deliting
folder1)

At the moment I use (RD "C:\Folder1" ~~ and MD "C:\Folder1")but
it has some side effects.

CHDIR *into* the directory (making it the Current Directory),
then issue
RD . /q /s

This will erase all files in the current directory and sub-
directories, all the sub-directories of the current directory.
If will produce a harmless error. If will fail on items currently
in use by another process or if the account has insufficient
permissions to delete. Be as careful with RD /s /q as with the old
DELTREE! See RD /? on your OS to confirm the switches.
 
J

Jerold Schulman

Hello all

can any one help?

I need to clean few folders using a batch file ..but I couldn't find a
way to delete subdirectories (Without deleting Root folder)

Eg:
if we have this tree:
C:\Folder1\folder2\files 1 2 3 etc
C:\Folder1\folder3\files 1 2 3 etc
C:\Folder1\folder4\folder5\files 1 2 3 etc
C:\Folder1\files 1 2 3 etc

I need to del (erase everything in "C:\Folder1" without deliting
folder1)

At the moment I use (RD "C:\Folder1" ~~ and MD "C:\Folder1")but it has
some side effects.

Thank you all for help...


See Deltree.bat at tip 617 in the 'Tips & Tricks' at http://www.jsiinc.com

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top