Solved

Batch file question/issue

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

696 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