Support Forums
FileTerminator Batch/CMD Script - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Computer Support Topics (https://www.supportforums.net/forumdisplay.php?fid=4)
+---- Forum: Microsoft Support (https://www.supportforums.net/forumdisplay.php?fid=5)
+---- Thread: FileTerminator Batch/CMD Script (/showthread.php?tid=21852)



FileTerminator Batch/CMD Script - AceInfinity - 08-31-2011

Here's a demo of a new script i've been working on. This one is different so be sure you view the video to get an idea of how it works.

[yt]http://www.youtube.com/watch?v=nsdfK_vR9LQ[/yt]

What this does is it takes the file you dropped onto the batch, and reads the filepaths to the files specified on each line that determines what it deletes. You can use a * wildcard as shown in the video to delete files.

It creates a Termination_Log file which you can open in notepad that contains the file deletion script that you used in case you need it for reference.

If you want to delete all files of a file extension:
Code:
*.fileextension

Or if you want to delete all files in all file extensions with a specific filename:
Code:
filename.*

Make sure you use a full filepath to the files you want to delete. Don't use anything but the filepath, no quotes, no commas, etc...
Example:
Code:
C:\MyUsername\Something\Something\SomeFile.FileExtension

If you use a wildcard, it will ONLY delete the files in the same directory as the one you specify to look for the files using the wildcard. It won't look in subdirectories, just to make this batch script a little safer. I've also put in a confirmation message at the beginning in case you accidentally drop a file on the batch script.

Here's the batch script: I save it with the .cmd extension, but you can use .bat for this script as well.
Code:
@echo off
Title Ace's FileTerminator
mode con: cols=55 lines=10
set errorh="%1"
set val=0

echo.This script will delete all of the files specified
echo.on each line of the file you dragged over this
echo.batch file. If only a filename was specified
echo.the script will look in the same directory of the
echo.batch file for that filename to delete.
echo.
echo Are you sure you want to delete the files^?
echo.
echo.   [Y] - Continue
echo.   [Q] - Quit and Exit
echo.

choice /c:YQ>nul
if errorlevel 2 exit

mode con: cols=75 lines=20
echo Ace's File Terminator>Termination_Log
echo %Date% - [%Time%]>>Termination_Log
echo.>>Termination_Log
echo Current Directory: %CD%>>Termination_Log
echo.>>Termination_Log

echo Deleting File^(s^):
echo.

for /f "tokens=*" %%i in ('type "%errorh%"') do (
    del /f /q "%%i">nul
    echo.  ^> Deleting File^(s^): %%i>>Termination_Log
    echo.  ^> %%i
    set /a val+=1
)

echo. >>Termination_Log
echo -- Created by Ace ^(2011^) -- >>Termination_Log

echo.
echo %val% file^(s^) have been deleted
echo Press any key to finish...
pause>nul



RE: FileTerminator Batch/CMD Script - Prominent - 08-31-2011

That's a great script you made ! I will test it in a few hours .