-2

Is it possible to loop this to rename all the PDFs in a Folder using this code? I am not that great with Windows Batch Scripting at least in terms of Loops and Variable Setups.

@echo off
pdftotext "XYZ.pdf"
rem set /p title=< "XYZ.txt":
set /p title=< "XYZ.txt" 
ren "XYZ.pdf" %title%.pdf
pause

1 Answers1

0

You will want to capture the output of the DIR command with a FOR /F command. This is necessary because a standard FOR command could potentially try to process a file that has already been renamed.

This is untested as I do not have the software you are using to convert PDF files.

@echo off

FOR /F "delims=" %%G IN ('dir /a-d /b *.pdf') DO (
    pdftotext "%%~G"
    set /p title=<"%%~nG.txt"
    setlocal enabledelayedexpansion
    ren "%%~G" "!title!.pdf"
    endlocal
)
Squashman
  • 13,649
  • 5
  • 27
  • 36