-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename.bat
44 lines (33 loc) · 1.02 KB
/
rename.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@echo off
setlocal enabledelayedexpansion
:: Allow user to browse for folder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please choose a folder',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "folder=%%I"
if "%folder%"=="" (
echo No folder selected. Exiting...
exit /b
)
echo Selected folder: %folder%
:: Confirm with user
set /p "confirm=Are you sure you want to rename all files in this folder? (Y/N): "
if /i "%confirm%" neq "Y" (
echo Operation cancelled. Exiting...
exit /b
)
:: Initialize counter
set "count=1"
:: Rename files
for %%F in ("%folder%\*.*") do (
set "oldName=%%~nxF"
set "extension=%%~xF"
:: Format the count to have leading zeros
set "newName=0000!count!"
set "newName=!newName:~-4!!extension!"
ren "%%F" "!newName!"
echo Renamed: !oldName! to !newName!
set /a "count+=1"
)
echo.
echo Renaming complete. %count% files were renamed.
pause