Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

delete files in a folder excluding some sub folders

Posted on 2013-01-08
5
Medium Priority
?
996 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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 57

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Here's a look at newsworthy articles and community happenings during the last month.
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

688 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