Last active
August 20, 2025 09:08
-
-
Save ruturajpatki/6a7f51eb345651462149a90409d669ab to your computer and use it in GitHub Desktop.
Windows Batch file to rename a file by removing a specific text from the filename and then move the file to selected folder. Place the script inside the same folder where the files to be renamed are stored. The script will ask you the folder name to move files after rename (it will create the folder if does not exist), the text to be removed fro…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal enabledelayedexpansion | |
| :: Prompt user for the folder name | |
| set /p foldername="Enter the folder name to save files to: " | |
| if not exist "%foldername%" mkdir "%foldername%" | |
| :: Prompt user for the string to remove from filenames | |
| set /p removestring="Enter the string to remove from filenames (e.g., sigma-): " | |
| :: Prompt user for the file extension | |
| set /p extension="Enter the file extension (e.g., png): " | |
| :: Prompt user to choose between copy or move | |
| set /p action="Do you want to COPY or MOVE the files? (copy/move): " | |
| if /i "%action%" neq "copy" if /i "%action%" neq "move" ( | |
| echo Invalid choice. Please enter either "copy" or "move". | |
| pause | |
| exit /b | |
| ) | |
| :: Loop through all files with the specified extension and rename/copy or move them | |
| for %%F in (*%removestring%*.%extension%) do ( | |
| set "filename=%%~nxF" | |
| set "newname=!filename:%removestring%=!" | |
| if /i "%action%"=="copy" ( | |
| copy "%%F" "%foldername%\!newname!" >nul | |
| ) else ( | |
| move "%%F" "%foldername%\!newname!" >nul | |
| ) | |
| ) | |
| echo Files %action%ed and renamed successfully. | |
| pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment