Solved

delete files in a folder excluding some sub folders

Posted on 2013-01-08
5
951 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 51

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

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
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 …
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

747 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