title: Python - read excel file into a list and rename files in a folder
body: <p>We have an excel file with 2094 rows and 3 columns structured like so:</p>
  
  <blockquote>
    <p>Employee Old ID | Employee Name | Employee New ID</p>
    
    <p>007219 | John Doe | 001234</p>
    
    <p>The end result being: John Doe 001234.jpg</p>
  </blockquote>
  
  <p>We have a folder with employee photos labels by their Old IDs and we want to read the excel file and then copy and rename the photos with the new ID.</p>
  
  <p><strong>Issue with the code</strong> - it stops after it copies and renames the first photo. I presume I need to adjust the last for loop but I am drawing a blank on how to get it to iterate.</p>
  
  <p><em>Notes: I tried to make the code flexible by including a file dialog folderSource. Additionally, I am new to Python so if you see ways to clean up the code by all means let me know, I added some questions in the comments in the code:</em></p>
  
  <pre><code>import openpyxl
  import os
  import shutil
  from tkinter import *
  from tkinter import filedialog
  
  root = Tk()
  root.withdraw()
  
  # File with file name data
  # Add the file name
  file_names = openpyxl.load_workbook(filedialog.askopenfilename())
  # Add the sheet name - can you make this more flexible? 
  file_names_sheet = file_names['piclist2']  
  
  # Select the source folder with files in it
  folderSource = filedialog.askdirectory()
  
  # New Folder Name - is there a filedialog way to flexibly create this?
  folderDestination = 'SSL Photos Renamed'
  
  # Takes: start cell, end cell, and sheet you want to copy from.
  def copyRange(startCol, startRow, endCol, endRow, sheet):
      rangeSelected = []
      # Loops through selected Rows
      for i in range(startRow, endRow + 1, 1):
      # Appends the row to a RowSelected list
          rowSelected = []
          for j in range(startCol, endCol + 1, 1):
              rowSelected.append(sheet.cell(row=i, column=j).value)
      # Adds the RowSelected List and nests inside the rangeSelected
      rangeSelected.append(rowSelected)
  
  return rangeSelected
  
  
  def renameFiles():
      print('Processing...')
  
      # Make a folder for the files
      current_directory = os.getcwd()
      folder_n_path = os.path.join(current_directory, folderDestination)
      print("Files saved to: " + folder_n_path)
      try:
      newFolder = os.makedirs(folder_n_path)
  
  except:
      print("Folder already exists")
      return
  
  # Get the Data to make the file names
  selectedRange = copyRange(1, 1, 2, 2, file_names_sheet)
  print(selectedRange)
  
  for i, filename in zip(selectedRange, os.listdir(folderSource)):
      print(filename)
      file_name = str(i[0]) + " " + i[1] + ".jpg"
      filename = os.path.join(folderSource, filename)
      file_name = os.path.join(folderDestination, file_name)
      shutil.copy(filename, file_name)
      print("Done")
  
  go = renameFiles()
  </code></pre>
  
  <p>I believe the issue is in the last bit of code but I cannot figure out how to do the loop. Thoughts?</p>