Solved

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

Posted on 2008-06-18
10
959 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Are you unable to synchronize your OST (Offline Storage Table) file with Microsoft Exchange Server? Is your OST file exceeding 2 GB size limit? In Microsoft Outlook 2002 and earlier versions, there is a 2 GB size limit for the OST file. If the file …
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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