last day (16 days later) » 

8:54 AM
1
A: How to rename all the images in a directory with name coming from an excel cell values?

mf Al FafaTo rename all image files in your directory, you can try the following python program. Just run the python script and the files will be automatically renamed corresponding to excel cell values: import pandas as pd import xlrd import os import glob # Your directory mydir = (os.getcwd()).replace(...

 
Thanks for your input. But there's a problem with your code. You didn't account for the fact that we need to match that we need to compare the '1097' for the image with the image name. For example 'img1097' should be renamed only with a cell value that contains 'First_Second_img1097'. So 1097 should be the matching key here which is not here, I readjusted but now it is not working. So for your code, it is just renaming all the images with the cell values of the excel. Hope this makes it clear.
 
oh i see, i will update this to match with your purpose, wait for a while.
Hello @user11409134, i have just edited the code.
 
what is this '-4' doing in if (df['Name'][n][len(df['Name'][n])-4:]? I'm sorry I didn't get it here. I can't hardcode it like this as the name not necessarily will be in 4 letters.
 
'-4' means to get the last 4 digits of number of filename or cell value. Example : image file with the name is 'file1234.png', with '-4' we can get only the 4 digits of unique number, so the result is '1234'
 
Also, this is not working for my files.
But it's not necessairily has to be 4 letters
I can have 5 6 even 12 letters as the number.
so If I adjust your code and change the df name it's running but it's not changing the name.
 
8:56 AM
@user11409134 what's the problem ? Your file cannot be renamed ?
@user11409134 It can be modified to satisfy the requirements. to get only the length of number
 
No the file names are not getting renamed
for simplicity purpose I kept it 4 char images only but still it's not renaming
 
@user11409134 of course the filename would not be changed, because the column for all filenames is identified by column 'Name' in excel
@user11409134 don't change df['Name'] variable, if you change 'Name' so you must change the column identifier in excel too
may i see your files, so i can modify the code to satisfy to your requirements ?
 
no my df name and column name are different than what you've used so changed it like that
how can I share the file? I don't want to post it on the forum.
 
9:12 AM
you can send your images filename to my email : miftahf77@gmail.com
@user11409134 yes, you must make df name to be same with column name to make it works.
 
I have sent you
 
okay,
I went out for a moment to break the fast. Wait for a moment. I will let you know later.
 

  last day (16 days later) »