import csv import os file = os.path.join('U:\\CCM\\Store\\Assets\\GlobalFiles\\PickList', 'Headshots.csv') local_path = """U:\CCM\\Store\\WebPages\\Custom\\ImageCatTree\\Employee Pictures\\All""" server_path = """E:\\DEPLOYMENTS\\CCM\Store\\WebPages\\Custom\\ImageCatTree\\Employee Pictures\\All\\""" with open(file, 'w', newline='') as csvfile: writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) writer.writerow(['Value'] + ['Display']) for files in os.listdir(local_path): filename = os.fsdecode(files) if files.endswith('.jpg') and not files.startswith('MISSING'): value = server_path + files writer.writerow([value] + [files])