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

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
mce-man-itAsked:
Who is Participating?
 
glenn_1984Connect With a Mentor Commented:
rd drive:\folder /s

rd is remove directory...which also removes the files
0
 
Hendo1973Commented:
The deltree  command will delete a folder and all subfolders.
0
 
mce-man-itAuthor Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
slam69Commented:
C:
cd\tempemp
del /Q *.*
0
 
slam69Commented:
would delete all files in the c:\tempemp directory
0
 
glenn_1984Commented:
In a batch file...

rdir.bat
   cls
  @echo Syntax is  rdir drive:\folder
   rd %1 /s
 
0
 
slam69Commented:
0
 
glenn_1984Commented:
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
 
mce-man-itAuthor Commented:
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
 
glenn_1984Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.