0

Please can you help. How can I rename pdf files to include the parentfolder name as the prefix, and adding DRAFT as a suffix?

For example, for parent folder name \ABCDEF:

  • xyc123.pdf
  • fgh456.pdf

I would like it to look like this \abcdef:

  • abcdefDRAFT.pdf
  • abcdefDRAFT.pdf

Each pdf is always unique, and each folder is always unique.
I just need the corresponding .pdfs in each folder to match the folder name.

I am new to scripting, and I would like to write and run the script using notepad
(I am not able to download any 3rd party software). Thank you.

Io-oI
  • 7,588
  • 3
  • 12
  • 41

1 Answers1

0

For command line in same folder (top-level folder tree):


cd /d "c:\folder_target\" & for /f tokens^=* %i in ('dir/b/s/a:-d')do ren "%~fi" "%~niDraft%~xi"

For bat/cmd file:


@echo off 

cd /d "c:\folder_target\"
for /f tokens^=* %%i in ('dir/b/s/a:-d')do ren "%%~fi" "%%~niDraft%~xi"


Additional resources:

Io-oI
  • 7,588
  • 3
  • 12
  • 41