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

From rbachwiki
Jump to navigation Jump to search
(Created page with "<pre> import os import pandas as pd import shutil os.chdir('C:\\Users\\bacchas\\Downloads\\test') data = pd.read_excel(r"rename.xlsx") orginal = "C:\\Users\\bacchas\\Downloads\\test\\original" dest = "C:\\Users\\bacchas\\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...")
 
Line 23: Line 23:


</pre>
</pre>
==[[#top|Back To Top]] - [[Python|Category]]==
[[Category:Python]]

Revision as of 17:41, 24 March 2023

import os
import pandas as pd
import shutil

os.chdir('C:\\Users\\bacchas\\Downloads\\test')
data = pd.read_excel(r"rename.xlsx")
orginal = "C:\\Users\\bacchas\\Downloads\\test\\original"
dest = "C:\\Users\\bacchas\\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)

Back To Top - Category