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
#1
Hi all,
I'm trying various ways to rename a bunch of pdf's in a directory. 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. Just to be tidy, I'd like to remove the "Layout (1) .pdf" and just keep the original file name that autocad has.

This is what I have so far:
###Script to remove Layout (1)
###from the filename that gets
###generated from autocad and
###adobe pdf batch plots - LAME!
###
###deep_logic 02/26/19
###
import os, sys, re, glob

from glob import glob
from os import rename

for fileName in os.listdir(r'c:\\TESTZ'):
    os.rename(fileName, fileName.replace("Layout (1)", "__"))
The filename length does change - that's why it's not as easy as using dict or a variation thereof.

The code doesn't do ANYTHING - it just hangs. So, if anyone could help a coder out...

I'm on python 2.7 and windows 10.

Many thanks
"Human history becomes more and more a race between education and catastrophe." - H. G. Wells (1866-1946)
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,263 Apr-19-2022, 07:06 AM
Last Post: Gribouillis
  Rename Multiple files in directory to remove special characters nyawadasi 9 6,575 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