Last active
December 18, 2024 18:06
-
-
Save psiborg/c333bbf967f0dec8ba06f36fd83a9074 to your computer and use it in GitHub Desktop.
Drag-and-drop files from Windows Explorer on to this batch script to rename them
This file contains 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 | |
:: Script to rename files: lowercase and replace spaces with underscores | |
setlocal enabledelayedexpansion | |
:: Check if any files were passed | |
if "%~1"=="" ( | |
echo Usage: Drag and drop files onto this script to rename them. | |
echo The script will rename files to lowercase and replace spaces with underscores. | |
pause | |
exit /b | |
) | |
:: Initialize counter | |
set "count=0" | |
:: Loop through all the dropped files | |
for %%F in (%*) do ( | |
set "filename=%%~nF" | |
set "extension=%%~xF" | |
:: Convert to lowercase and replace spaces with underscores | |
set "newname=!filename: =_!" | |
set "newname=!newname!!extension!" | |
:: Convert the name to lowercase using PowerShell | |
for /f "delims=" %%L in ('powershell -Command "(\"!newname!\").ToLower()"') do set "lowername=%%L" | |
echo !filename!!extension! to !lowername! | |
:: Rename the file | |
ren "%%~F" "!lowername!" | |
:: Increment counter | |
set /a count+=1 | |
) | |
:: Display results | |
echo %count% file(s) have been renamed. | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment