• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Batch file question/issue

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
regsamp
Asked:
regsamp
  • 2
  • 2
2 Solutions
 
Shift-3Commented:
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
 
regsampAuthor Commented:
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
 
Shift-3Commented:
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
 
A_Ridiculously_Long_Unique_NameCommented:
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
 
A_Ridiculously_Long_Unique_NameCommented:
PS I haven't tested this as I don't have a destructable drive!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now