Answer the question
In order to leave comments, you need to log in
How to bulk rename numbered PDF files?
Good time of the day!!!
In my work, I have to make registers with a list of files in a folder.
The sequence of files must be saved in the registry regardless of the numbering (for example: 1. AOCP_#1 2.AOCP_#2 3.AOCP_#2), if you simply manually delete the numbering, the order will be corrected (AOOK_#2, AOCP_#1, AOCP_# 2). It is also necessary to replace any existing numbering such as 1,2,3 or 01,02,03 with 001,002,003, again preserving the sequence of files after renaming.
I throw off my experience on renaming files by type 001,002,003. Batch file
This batch file numbers pdf files in a folder by type 001,002,003
@echo off
setlocal enableextensions EnableDelayedExpansion
set n=1000
for %%a in (*) do if /i "%%~xa"==".pdf" (
set /a n+=1
set num=!n:~1!
call ren "%%a" "!num!.%%a"
)
pause
Answer the question
In order to leave comments, you need to log in
The difficulty is that you need to extract its number from the file name and add the required number of zeros.
You can extract the number by driving the filename into a for /f loop and dividing it into tokens. Of the tokens, we are only interested in 1 token (number):
for %%a in (*) do if /i "%%~xa"==".pdf" for /f "tokens=1,* delims=." %%b in (%%a) do (
echo %%b
)
for /?
set /?
Take a closer look at vbs or PowerShell, the first one is generally everywhere. The second on more or less modern machines. It's just that cmd is somewhat limited by default.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question