[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Batch file question/issue

Posted on 2009-04-08
5
Medium Priority
?
295 Views
Last Modified: 2013-11-13
We are trying to create a batch file that will delete files that end with a certain extension off of network drives.  For example .bak or .txt and we are new at this and do not want to make any mistakes.  If someone could please post example script it would be greatly appreciated.  
0
Comment
Question by:regsamp
[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
  • 2
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 1600 total points
ID: 24097035
To delete all files with a particular extension off of a drive you can use the DEL command like so:
del /s /q x:\*.txt

This would delete all .txt files from the x: drive and all subfolders.  Use this with caution, as it doesn't prompt for confirmation and deletes files permanently without sending them to the Recycle Bin.

Please provide more details if there is more that you want the script to do.  Do you want it to detect which drives are network drives and then perform the action on all of them?
0
 

Author Comment

by:regsamp
ID: 24097116
Thank you shift. That looks like what we needed.  We want to be able to just edit the script and choose which mapped drive to run it on so that looks good.  
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24097345
You can also add the /f switch to force deletion of read-only files.

If you're looking to prevent users from saving particular files types to their network drives, you might want to look into the File Server Resource Manager feature of Server 2003 R2.  This lets you set custom file screens which can block certain file types.
0
 
LVL 1

Assisted Solution

by:A_Ridiculously_Long_Unique_Name
A_Ridiculously_Long_Unique_Name earned 400 total points
ID: 24114551
You could try

del /s /q %1\*.txt

Where %1 is an argument to your bat file

Eg: Your bat file will contain
del /s /q %1\*.txt

If you save it as killem.bat you would invoke it as

killem x:

Again, as Shifty says, caution!!!


0
 
LVL 1
ID: 24114571
PS I haven't tested this as I don't have a destructable drive!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Read about the ways of improving workplace communication.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

650 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