Difference between revisions of "Rename files using excel as source template"

From rbachwiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:


</pre>
</pre>
<pre>
'''Excel Spreadsheet'''
 
<b>oldname newname
004.jpg house.jpg
004.jpg house_1.jpg
005.jpg bulldog.jpg
005.jpg dog.jpg
003.jpg tree.jpg
001.jpg pizza.jpg
002.jpg cat.jpg
001.jpg pizza2.jpg
002.jpg cat_1.jpg
 
</pre>
{|class="wikitable" style="padding:5px;border:1px solid black;"
{|class="wikitable" style="padding:5px;border:1px solid black;"
!Oldname
!oldname
!Newname
!newname
|-
|-
|004.jpg
|004.jpg

Latest revision as of 19:21, 24 March 2023

import os
import pandas as pd
import shutil

os.chdir('C:\\Users\\one\\Downloads\\test')
data = pd.read_excel(r"rename.xlsx")
orginal = "C:\\Users\\one\\Downloads\\test\\original"
dest = "C:\\Users\\one\\Downloads\\test\\img"

old = data['oldname']
new = data['newname']


for (old, new) in zip(old,new):
         
         full_file_name = os.path.join(orginal,old)
         full_file_name_old = os.path.join(dest,old)
         full_file_name_new = os.path.join(dest,new)
         shutil.copy(full_file_name,dest)
         os.rename(full_file_name_old, full_file_name_new)
         print(full_file_name, full_file_name_new)

Excel Spreadsheet

oldname newname
004.jpg house.jpg
001.jpg cat.jpg
002.jpg mouse.jpg
003.jpg hosue.jpg

Back To Top - Category