In a batch file can be used the following code:
@echo off
setlocal EnableExtensions EnableDelayedExpansion
for /F "delims=" %%I in ('dir /AD-L /B 2^>nul ^| %SystemRoot%\System32\findstr.exe /R /X "[0123456789][0123456789]*"') do (
set "FolderName=00000%%I"
set "FolderName=!FolderName:~-6!"
if not !FolderName! == %%I ren %%I !FolderName!
)
endlocal
To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
dir /?
echo /?
endlocal /?
findstr /?
for /?
if /?
ren /?
set /?
setlocal /?
Read the Microsoft documentation about Using command redirection operators for an explanation of 2>nul
and |
. The redirection operators >
and |
must be escaped with caret character ^
on FOR command line to be interpreted as literal characters when Windows command interpreter processes this command line before executing command FOR which executes the embedded dir
command line with output filtered additionally by findstr
with using a separate command process started in background with cmd.exe /c
and the command line within '
appended as additional arguments.