Python Forum
Renaming PDF files using Excel data - Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Renaming PDF files using Excel data - Python
#5
I solved my problem...Here is the solution:

import os, re
import xlrd

def rename_pdfs():

    path = r"C:\\Users\\...\\original"
    excelFile = xlrd.open_workbook(r"C:\\Users\\...\\data.xlsx")
    workSheet = excelFile.sheet_by_index(0)
    fileNum = 1

    for rownum in range(workSheet.nrows):
        inv = workSheet.cell_value(5+rownum, 4)
        for index in re.finditer("1718-", inv):
            rfr = inv[index.end():index.end() + 10]
            newFilename = workSheet.cell_value(5+rownum, 1) + " " + "1718-" + rfr
            os.rename(os.path.join(path, str(fileNum)+".pdf"), os.path.join(r"C:\\Users\\...\\renamed", newFilename+".pdf"))
            fileNum += 1

if __name__ == "__main__":
    rename_pdfs()
Reply


Messages In This Thread
RE: Renaming PDF files using Excel data - Python - by okanaira - Mar-20-2018, 07:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Information automatic document renaming lisa_d 2 482 Mar-20-2024, 06:34 PM
Last Post: Pedroski55
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 1,413 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  Copy Paste excel files based on the first letters of the file name Viento 2 628 Feb-07-2024, 12:24 PM
Last Post: Viento
  Copy data from Excel and paste into Discord (Midjourney) Joe_Wright 4 2,395 Jun-06-2023, 05:49 PM
Last Post: rajeshgk
  script to calculate data in csv-files ledgreve 0 1,253 May-19-2023, 07:24 AM
Last Post: ledgreve
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,270 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 2,178 Dec-12-2022, 08:22 PM
Last Post: jh67
  How to loop through all excel files and sheets in folder jadelola 1 4,941 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  Trying to Get Arduino sensor data over to excel using Python. eh5713 1 1,997 Dec-01-2022, 01:52 PM
Last Post: deanhystad
  Appending a row of data in an MS Excel file azizrasul 3 1,350 Nov-06-2022, 05:17 PM
Last Post: azizrasul

Forum Jump:

User Panel Messages

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