Skip to content
Advertisement

How to rename files from old to new from csv file using python?

I have a CSV file which has two columns:

JavaScript

I have more than a thousand pictures which I need to rename using this method. Can this be done using python? Thanks a lot.

Advertisement

Answer

You can use zip to iterate over pairs of corresponding items:

JavaScript

As you are batch processing a large number of files, it might also be worth doing a try so that if one of the renames fails (e.g. one of the files was already renamed), it doesn’t stop the whole operation. For example:

JavaScript

Note that I am taking your question to mean the raw contents of your CSV file looks like:

JavaScript

and that you have read it in using:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement