简体   繁体   中英

Batch Script - Copy files from file list to location in filelist

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?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM