Feb-27-2018, 08:15 AM
ok what i am trying to do is ...writing a module that will read csv , pick file names from there look into the directory where these files resides and then move them to the destination folder...i think i had some error in the above code..i have redone the same code..
but now it says
please help me to correct this code so that i can move selected files which are mentioned in csv to new directory...i have attached new cvs file for this code also by editing the original post..
but now it says
Error:no file path or directory "filepath"
below is the codeimport os import shutil import csv import sys csv_file = "maharera.csv" existing_path_prefix = "D:\maharera" new_path_prefix = "D:\movement" def main(argv): # TODO: this should do some error checking or maybe use optparse csv_file, existing_path_prefix, new_path_prefix = argv[1:] with open(csv_file, 'r') as f: reader = csv.reader(f) for row in reader: # Assuming the column in the CSV file we want is the first one filename = row[0] filepath = row[1] if filename.startswith(existing_path_prefix): filename = filename[len(existing_path_prefix):] new_filename = os.path.join(new_path_prefix, filename) #print ('Copying %s to %s...' % filename, new_filename), #print ('Copying %s to %s...' % filepath, new_filename) #Changed shutil.copy(filepath, new_filename) #Changed print ('done.') #print ('All done!') if __name__ == '__main__': main(sys.argv)i read the code here...https://stackoverflow.com/questions/29850220/read-filenames-from-csv-and-then-copy-the-files-to-different-directory
please help me to correct this code so that i can move selected files which are mentioned in csv to new directory...i have attached new cvs file for this code also by editing the original post..