Link to home
Get AccessLog in
Avatar of Pete
PeteFlag for United Kingdom of Great Britain and Northern Ireland

asked on

delete files in a folder excluding some sub folders

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.
Avatar of thombeck
thombeck

if the folder contains no subfolder, you can use
del c:\Temp\*.* (if c:\Temp\ is the folder)
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)
Avatar of Anwar Saiah
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.
ASKER CERTIFIED SOLUTION
Avatar of thombeck
thombeck

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
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