Solved

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

Posted on 2008-06-18
10
961 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 250 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Industry Leaders: 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!

Question has a verified solution.

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

If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
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…
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…

733 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