Deleting specific file extension using batch script

Windows batch script that can be used to delete multiple file extensions from a folder:

@echo off

REM Set the folder path and file extensions to delete
set folderPath=C:\myFolder
set fileExtensions=.tmp .temp .bak

REM Loop through the file extensions and delete the files
for %%F in (%fileExtensions%) do (
  del /F /Q "%folderPath%\*%%F"
)

REM Display a message when the files have been deleted
echo All files with the specified extensions have been deleted from the %folderPath% folder.

This script uses a for loop to iterate over the list of file extensions specified in the fileExtensions variable. For each file extension, it uses the del command to delete all files with that extension from the specified folder. It then displays a message when all of the files have been deleted.

To use this script, you would need to modify the folderPath and fileExtensions variables at the beginning of the script to specify the correct folder path and the file extensions you want to delete. You can also add additional file extensions to the fileExtensions variable if needed.

Once you have customized the script, you can run it from the command line by navigating to the directory where the script is saved and typing batchScriptName.bat, where batchScriptName is the name of the script file. This will execute the script and delete the specified file extensions from the specified folder. You can use this script as a starting point for creating your own batch scripts for managing files and folders on your system.

Leave a Comment

Your email address will not be published. Required fields are marked *