0

I have a number of images in a folder, belonging to 3 different categories with same extension, and I have an excel file containing the image file name in one column and the category in another. I want to divide the main image folder into different category wise subfolders. Can someone tell how to code this, it would be really helpful Thanks!

Note - The first column in excel sheet has name of images, and the second column has categories. I have one folder that contains all the images in that single folder, and I want to create categorical wise folder, based on data given through excel sheet

oprah
  • 1
  • Is this a one-time only thing? Easy way with no programming would be to save your Excel file as a CSV file, and then use a text editor to rearrange that into a batch file to do the renames. – Tim Roberts Jun 30 '21 at 03:14
  • yes, the rearrangement can be done. But after that, when new folders are to be created, with same type of image in one folder, how to do that? – oprah Jun 30 '21 at 03:17
  • Since you haven't showed us your data, no one here can provide any code. – Tim Roberts Jun 30 '21 at 03:27
  • can u guide upon the approach, if possible! – oprah Jun 30 '21 at 03:45
  • Use [pandas](https://pythonspot.com/read-excel-with-pandas/) to read the column data, use [mkdir](https://stackoverflow.com/questions/273192/how-can-i-safely-create-a-nested-directory-in-python) to create the sub folders, then [copyfile](https://stackoverflow.com/questions/123198/how-can-a-file-be-copied) to copy and move your images – Marcucciboy2 Jun 30 '21 at 05:11
  • 1
    As a human being, how would you do it? You'd look at each line one by one. Given the category, you'd prepend a folder name to the file name, and do a `rename` command. That's what your script has to do. – Tim Roberts Jun 30 '21 at 22:04

0 Answers0