I am pretty much copying the code from this thread (Python - copying specific files from a list into a new folder), but can't get it to work and can't see what is wrong. Any insight?
csv file has image name (i.e. image.png) in first column, and significant/insignificant in the next column, but that is not used yet. Just testing it on 10 files right now. The 10 files are in the folder I want to copy from.
# ----------------------------------------IMPORT PACKAGES -------------------
import os
import shutil
import csv
# ------------------------------------copy IMAGES using --------------
# ----------------------GET PATHS----------------------------------------
folderpath = os.getcwd() # /home/ubuntu/Deep-Learning/FinalProject/data_random
destination = '/home/ubuntu/Deep-Learning/FinalProject/data_subset'
# ------------------LIST OF IMAGE NAMES----------------------------------
filestofind = []
with open("labels_test.csv", "r") as f:
filestofind = [x[0] for x in csv.reader(f) if x]
print(filestofind)
# successfully gets list of image names
# [' image1.png', ' image2.png', ...'image10.png]
# ------FIND IMAGE IN FOLDER AND COPY AND MOVE TO DESTINATION FOLDER----
for filename in filestofind:
print('filename1',filename) #filename1 image1.png - looks ok
for file in folderpath(filename):
print('filename2',filename) #It is seeing this as a string and
#iterating through the string
# says it is not callable
# filename2 /
# filename2 h
# filename2 o
# filename2 m
# expected to look for filename1 above in the folderpath
if os.path.isfile(filename):
shutil.copy(filename, destination)
else:
print('file does not exist: filename')
print('All done!')