Solved

Batch file question/issue

Posted on 2009-04-08
5
280 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
  • 2
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 400 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Online collaboration can help businesses be more efficient, help employees grow their skills and foster a team environment.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

939 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

16 Experts available now in Live!

Get 1:1 Help Now