Solved

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

Posted on 2008-06-18
10
956 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 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now