Python Forum
rename many pdf'S in a directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rename many pdf'S in a directory
#2
(Feb-26-2019, 07:30 PM)deep_logic Wrote: I have autocad batch print 50 files to adobe pdf. The problem is the default filename will add "Layout (1) .pdf" at the end of the filename.
How dos the raw filename look?
Let say as you say just add fooLayout (1).pdf hello worldLayout (2).pdf
import os
import re

for file_name in os.listdir('.'):
    if file_name.endswith('.pdf'):
        new_name = re.sub(r'L.*\)', '', file_name)
        # Always test print before doing chages to files
        print(file_name, new_name)
        #os.rename(file_name, new_name)
Output:
foo.pdf hello world.pdf
Reply


Messages In This Thread
rename many pdf'S in a directory - by deep_logic - Feb-26-2019, 07:30 PM
RE: rename many pdf'S in a directory - by snippsat - Feb-27-2019, 01:23 PM
RE: rename many pdf'S in a directory - by ddrillic - Feb-27-2019, 10:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Closing logger to rename directory malcoverc 1 1,281 Apr-19-2022, 07:06 AM
Last Post: Gribouillis
  Rename Multiple files in directory to remove special characters nyawadasi 9 6,720 Feb-16-2021, 09:49 PM
Last Post: BashBedlam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020