?
Solved

How to delete all folders in a directory using a batch file?

Posted on 2008-06-18
10
Medium Priority
?
965 Views
Last Modified: 2008-06-19
I am trying to wirte a batch file which copies then deletes all files and folders from the Desktop when logging in.

I have used xcopy to copy everything in a set location and am able to delete all the files but not the folders.

We are using XP.

Any help would be great,

David
0
Comment
Question by:mce-man-it
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:Hendo1973
ID: 21812352
The deltree  command will delete a folder and all subfolders.
0
 
LVL 16

Accepted Solution

by:
glenn_1984 earned 750 total points
ID: 21812406
rd drive:\folder /s

rd is remove directory...which also removes the files
0
 

Author Comment

by:mce-man-it
ID: 21812432
When i use the deltree command i get the error 'this is not recognized as an internal or external command'

Also i didnt mention we wont know the name of the folders we want to delete.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:slam69
ID: 21812451
C:
cd\tempemp
del /Q *.*
0
 
LVL 25

Expert Comment

by:slam69
ID: 21812453
would delete all files in the c:\tempemp directory
0
 
LVL 16

Expert Comment

by:glenn_1984
ID: 21812454
In a batch file...

rdir.bat
   cls
  @echo Syntax is  rdir drive:\folder
   rd %1 /s
 
0
 
LVL 25

Expert Comment

by:slam69
ID: 21812482
0
 
LVL 16

Expert Comment

by:glenn_1984
ID: 21812520
you need to know the folder name.
If you just want to delete files from whatever folder they are in, go to the root of the drive and type
del filename.ext /s /q

or

del *.ext /s /q
0
 

Author Comment

by:mce-man-it
ID: 21812858
Thanks for all your answers. It is now working with 'rd c:\Documents and Settings\User\desktop /s' .

But even though shortcut icons are in the all users desktop folder it deletes them aswell.

Any reasons why?

0
 
LVL 16

Expert Comment

by:glenn_1984
ID: 21816801
A shortcut is just that. It is not the exact same as a direct icon link to an actual program.
If the actual folder is deleted, the shortcut to it is useless.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
Integration Management Part 2
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question