Microsoft Office Forums Batch add suffix to PDF files in folder

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-29-2016, 09:34 PM
Dave T Dave T is offline Batch add suffix to PDF files in folder Windows 7 64bit Batch add suffix to PDF files in folder Office 2007
Advanced Beginner
Batch add suffix to PDF files in folder
 
Join Date: Nov 2014
Location: Australia
Posts: 38
Dave T is on a distinguished road
Default Batch add suffix to PDF files in folder

Hello All,

I am after a *.bat file that will add some specific text before the .PDF extension.

For example I have hundreds of PDF's in a folder with different names, that look similar to the following:
PN00001.pdf


PN00123.pdf
PN00234.pdf

I would like to change them to by adding a ' - Calculations' suffix:
PN00001 - Calculations.pdf
PN00123 - Calculations.pdf
PN00234 - Calculations.pdf

I have previously used a bat file to create a text file of all the files with the folder it is run from and am hoping the PDF suffix file can be placed in a specific folder and only rename these PDF's that are within that folder.

Code:
dir /a /b /-p /o:gen >C:\WINDOWS\Temp\file_list.txt
start notepad C:\WINDOWS\Temp\file_list.txt
Any suggestions appreciated.

Regards,
Dave T
Reply With Quote
  #2  
Old 03-01-2016, 07:49 PM
macropod's Avatar
macropod macropod is offline Batch add suffix to PDF files in folder Windows 7 64bit Batch add suffix to PDF files in folder Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,617
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Only because I'm rusty on the batch processing language, I'd be inclined to generate a file listing, then open the file in Word and use a wildcard Find/Replace, where:
Find = (<[A-Z0-9]@>)(.pdf)
Replace = REN \1\2 ^34\1 - Calculations\2^34
Then save the file and run it as a batch file.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 03-01-2016, 08:07 PM
Dave T Dave T is offline Batch add suffix to PDF files in folder Windows 7 64bit Batch add suffix to PDF files in folder Office 2007
Advanced Beginner
Batch add suffix to PDF files in folder
 
Join Date: Nov 2014
Location: Australia
Posts: 38
Dave T is on a distinguished road
Default

Hello Paul,

I appreciate your reply.

I have never really had much to do with batch processing language either, but I found some examples that I was able to modify to suit my needs, although it probably can be done better.
The following adds ' - Capacity Calculations' before the .pdf extension, whilst retaining the original file name:

Code:
 
@ECHO OFF
REN *.pdf *.
REN *. *" - Capacity Calculations".
REN *. *.pdf
To sort the various PDF's I have had to pad the numbers out so there are five digits after the PN prefix. Again I found an example I was able to modify:

Code:
@echo off
setlocal enableextensions enabledelayedexpansion
rem iterate over all PDF files:
for %%f in (*.pdf) do (
    rem store file name without extension
    set FileName=%%~nf
    rem strip the "PN"
    set FileName=!FileName:PN=!
    rem Add leading zeroes:
    set FileName=00000!FileName!
    rem Trim to only four digits, from the end
    set FileName=!FileName:~-5!
    rem Add "PN" and extension again
    set FileName=PN!FileName!%%~xf
    rem Rename the file
    rename "%%f" "!FileName!"
)
There probably are better methods out there but these two batch files get me through.

I will mark this post as solved, but am still hoping someone can show me a better way.

Regards,
Dave T

Last edited by Dave T; 03-01-2016 at 08:20 PM. Reason: Tying to find Solved button
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Word - Search Within Files Containing A String - Copy Files to New Folder jc491 Word VBA 0 01-09-2016 12:00 PM
Batch add suffix to PDF files in folder VBA batch file to insert text at end of 50 files slow, 90% CPU usage equalizer88 Word VBA 3 08-16-2015 04:56 PM
Batch add suffix to PDF files in folder Batch instruction works or ".doc" in folder, but not ".docx" raymondroe Word VBA 4 02-15-2015 01:19 AM
Remove Compatibility Mode on DOCX files (batch) w64bit Word 17 02-01-2015 06:02 AM
Batch add suffix to PDF files in folder how to batch update linked image files path? stanleyhuang Word 3 09-11-2014 12:51 AM


All times are GMT -7. The time now is 07:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft