Solved

Batch file question/issue

Posted on 2009-04-08
5
277 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 76
Math home work questions 5 62
how to update exe applicatio from internet ? 6 39
Java Loop 4 14
Communication between departments might not happen in two different languages, but they do exist in two different worlds. With different targets and performance goals the same phrase often means something completely different to each party. Learn ho…
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.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

706 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

12 Experts available now in Live!

Get 1:1 Help Now