Solved

delete files in a folder excluding some sub folders

Posted on 2013-01-08
5
969 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 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 54

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

752 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