Skip to content

Instantly share code, notes, and snippets.

Created February 5, 2018 17:23
Show Gist options
  • Save anonymous/2e4b9786fbb4f103407f2c35e5437092 to your computer and use it in GitHub Desktop.
Save anonymous/2e4b9786fbb4f103407f2c35e5437092 to your computer and use it in GitHub Desktop.
@ECHO OFF & setLocal EnableDelayedExpansion
:Start
REM Means comment, doesn't run anything
SET /P dirName=Please enter a directory:
IF "%dirName%"=="" GOTO :Start REM If the directory name is empty, go back to start.
:Confirmation
SET /P confirmation=Are you sure you want to change file names in %dirName%? (y/n):
REM Confirm if user typed correct directory name
REM Check if it exists
IF /I "%confirmation%" EQU "Y" goto :FileCheck
IF /I "%confirmation%" EQU "N" goto :Start
:FileCheck
IF exist %dirName% (
cd %dirName%
REM If it exists, change directory
goto :FileRename
)ELSE(
ECHO "File not found." ;Else file not found
)
REM Iterator, we count from 0.
:FileRename
set a=0
;How to set multiple file types
FOR /F "delims=" %%i in ('dir /B *.png *.jpg') do (
ren "%%i" "!a!.jpg" ;Rename it
set /a a+=1 ;Iterator +1
)
IF "%a%" >= 1 do(
ECHO "Changed %a% files" ;Display how many files were changed. ;Output for debugging
)ELSE(
ECHO "No files found."
)
REM Wait for user to hit key to end program.
PAUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment