简体   繁体   中英

Rename multiple files using a list of names on excel

I have a bunch of PDF files with random names, like 95456356.pdf, 7896548965.pdf and so on. I also have a list of names in an Excel file with all the names in a column. Can I write a code that would read that Excel file and then rename all PDF files in the same order, like the first file would be renamed to the name in the fisrt row in the excel file? I can copy and paste that column to a .txt file if that makes it easier.

You used the xlrd package to read your Excel file. A nice tutorial on how to read Excel files can be found here: https://www.geeksforgeeks.org/reading-excel-file-using-python/

With this package it should be relatively easy to write code with the desired behaviour:

  • You should be able to read one cell with the name you want to use for renaming the files
  • You should be able to read the filenames of the pdf files
  • You should be able to rename files using the os package (see here: How to rename a file using Python )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM