-2

I have two files (source and destination)

The source has the full path of a document:

N:\PRS\CVs\Original CVs\2008***, *** Orig CV Aug 08.doc

And the destination has the same, just with a different path:

E:TRIS\Documents\Candidate\Original Resumes\N\***, ***Orig CV Aug 08.doc

There are about 100k entries in each file seperated by a new line, how can i copy the source file to the destination file in bulk?

Owain Esau
  • 1,876
  • 2
  • 21
  • 34
  • Just to clarify: Do you want to copy 100k files from the _source file list_ to the locations on the _destination file list_? – DYZ Jan 19 '17 at 03:53
  • Yes that is correct, the destination file also has the filename at the end but i can remove the filename from them if need be. – Owain Esau Jan 19 '17 at 03:54
  • Are destination folders the same for all files or different? – DYZ Jan 19 '17 at 03:57
  • 1
    Possible duplicate of [Batch: Copy a list (txt) of files](http://stackoverflow.com/questions/6257948/batch-copy-a-list-txt-of-files) – DYZ Jan 19 '17 at 03:59
  • Different, each file is put into a different folder based on the last name shown in the document name, in the case above /N/ – Owain Esau Jan 19 '17 at 04:01
  • Experiment with something like this: `cmd /s /v:on /c "1>copyall.bat 3 – Eryk Sun Jan 19 '17 at 08:59

1 Answers1

2

Since you tagged your question with the python tag, I assume you are ok with using Python.

A possible solution is to read the content of each file and then produce a batch file that would execute xcopy with each pair of file names. That file can be saved as a regular batch file and later executed:

infile1 = open("src.txt")
infile2 = open("dest.txt")
outfile = open("copyall.bat", "w")
# Assume the number of lines in both files is the same!
for src in infile1:
    src = src.strip().replace(r'"',r'\"')
    dest = infile2.readline().strip().replace(r'"',r'\"')
    command = '''xcopy "%s" "%s"\n''' % (src, dest)
    outfile.write(command)
outfile.close()

After you prepare the batch file, make sure to have a look into it before executing it! The first line of the file should look something like this:

xcopy "N:\PRS\CVs\Original CVs\2008***, *** Orig CV Aug 08.doc" "E:TRIS\Documents\Candidate\Original Resumes\N\***, ***Orig CV Aug 08.doc"
DYZ
  • 55,249
  • 10
  • 64
  • 93
  • Hi, This works really well. Unfortunately i am being forced to complete a change request form in order to just install python on the server this will be run on. I ran it locally on a few files and saw that the copyall.bat had the correct command in it so im confident this will work! – Owain Esau Jan 19 '17 at 04:24
  • Then, a really silly solution: open each list in Excel; keep the content of the source list in the second column; copy the content of the dest file into the third column; paste the word `xcopy` in each row of the first column; save the file as CSV with spaces as delimiters, and rename it to `copyall.bat`. – DYZ Jan 19 '17 at 04:27
  • Says invalid number of paramaters – Owain Esau Jan 19 '17 at 04:52
  • CMD, dont worry i figured it out. It needed quotations around the paths since there were spaces in it. That was no easy task though, excel with over 100k records gets a little iffy. – Owain Esau Jan 19 '17 at 06:35