Python Forum
copy files from one destination to another by reading filename from csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
copy files from one destination to another by reading filename from csv
#1
hi,

i want to move several file mentioned in csv to another folder path which is mentioned in code

i have several pdf's mentioned in the attached csv file, in csv file there is one column with the filename including it's path....but when i try to run this it says
Error:
File "C:\Users\prince.bhatia\Desktop\install\copying_module.py", line 10 "filename", "D:\maharera", "D:\maharera\copy" = argv[1:] ^ SyntaxError: can't assign to literal [Finished in 0.226s]
below is my code:
import shutil
import os
import csv
import sys

dataobj = {}
filename = "maharera.csv"


def main(argv):
    filename, "D:\maharera", "D:\maharera\copy" = argv[1:]
    with open(filename, "rb")as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            filename = row[0]
            filepath = row[1]

            if filename.startswith("D:\maharera"):
                filename = filename[len(existing_path_prefix):]

            newfile = os.path.join("D:\maharera\copy", filepath)
            print ('Copying %s to %s...' % filename, new_filename),
            shutil.copy(filename, new_filename)
if __main__ == "__main__":
    main(sys.argv)
#source = os.listdir("D:\maharera")
#print(source)
#destination = "D:\maharera\copy"

#for files in source:
#    if files.endswith(".pdf"):
#        shutil.copyfile(files, destination)
can anyone guide me in right direction since i have 15000 pdf out of which in files i have mentioned 501 which needed to move to another folder

Attached Files

.csv   maharera.csv (Size: 11.41 KB / Downloads: 612)
Reply


Messages In This Thread
copy files from one destination to another by reading filename from csv - by Prince_Bhatia - Feb-27-2018, 07:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 312 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy Paste excel files based on the first letters of the file name Viento 2 492 Feb-07-2024, 12:24 PM
Last Post: Viento
  Create new folders and copy files cocobolli 3 1,532 Mar-22-2023, 10:23 AM
Last Post: Gribouillis
  Copy only hidden files and folders with rsync Cannondale 2 1,067 Mar-04-2023, 02:48 PM
Last Post: Cannondale
  python move specific files from source to destination including duplicates mg24 3 1,138 Jan-21-2023, 04:21 AM
Last Post: deanhystad
  Rename part of filename in multiple files atomxkai 7 7,447 Feb-18-2022, 10:03 PM
Last Post: atomxkai
  Append files and add column with last part of each filename NiKirk 0 2,651 Feb-04-2022, 07:35 AM
Last Post: NiKirk
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,570 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Reading a copy-protected PDF CaptainCsaba 6 6,280 Oct-25-2021, 07:06 AM
Last Post: Caslenty
  Reading Multiple text Files in pyhton Fatim 1 1,964 Jun-25-2021, 01:37 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020