Skip to content

Instantly share code, notes, and snippets.

@myazdani
Last active August 29, 2015 14:22
Show Gist options
  • Save myazdani/6c66ad4449374aa7c082 to your computer and use it in GitHub Desktop.
Save myazdani/6c66ad4449374aa7c082 to your computer and use it in GitHub Desktop.
Copy Image paths specified in a CSV column to a specific directory
import pandas as pd
import os
import shutil
import sys
if len(sys.argv) < 1:
print "provide CSV file argument, followed by target directory argument,",\
" followed by which column to use from csv file (optional)"
elif len(sys.argv) < 4:
in_file = sys.argv[1]
target_path = sys.argv[2]
file_path_column_name = "file_path"
elif len(sys.argv) == 4:
in_file = sys.argv[1]
target_path = sys.argv[2]
file_path_column_name = "file_path"
df = pd.read_csv(in_file)
image_paths = list(df[file_path_column_name])
if not os.path.exists(target_path):
os.makedirs(target_path)
def copyFromListToPath(src_paths, dest_path):
for i in range(len(src_paths)): shutil.copy2(src_paths[i], dest_path)
copyFromListToPath(image_paths, target_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment