Solved

delete files in a folder excluding some sub folders

Posted on 2013-01-08
5
960 Views
Last Modified: 2013-01-08
I have a folder with various exe, dll, dat etc files in and 2 subfolders. i want to empty this folder of it files but leave the folders.
how can I do this via command line? I have 500 win7 computers to do this on.
I really want a single command rather than del *.exe
del *.dll
etc for each computer.
0
Comment
Question by:Pete
  • 3
5 Comments
 
LVL 2

Expert Comment

by:thombeck
ID: 38756166
if the folder contains no subfolder, you can use
del c:\Temp\*.* (if c:\Temp\ is the folder)
0
 
LVL 2

Expert Comment

by:thombeck
ID: 38756174
sry for the posting, here is the correct meaning:


if you only want to delete the file in folder ; not in the subfolder, you can use
del c:\Temp\*.* (if c:\Temp\ is the folder)
0
 
LVL 10

Expert Comment

by:aboo_s
ID: 38756181
are all the computers identical ? do they all have the same file structure?
If so you can create an autoexec.bat file that you can put on a usb drive and
move the usb drive between all the computers.

The autoexec.bat should of course hold all the command sequence:

del *.bat
del *.exe
etc..

you can create this file using windows' notepad.
0
 
LVL 2

Accepted Solution

by:
thombeck earned 500 total points
ID: 38756189
if you want to delete all files and all files from all subfolders, then use
del c:\TEMP\*.* /S /Q

--> the switch /s deletes all files from folder and from all subfolders
--> the switch /q disable the question for confirmation to delete

(can also be added if you want to delete the files only from the folder)
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 38756793
The DEL command can take multiple file names/patterns as well, so you can do:

del /s /q "c:\basedir\*.exe" "c:\basedir\*.dll"

~bp
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …

910 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

23 Experts available now in Live!

Get 1:1 Help Now