3

I want to copy large amount of big files from folder A to folder B.

I have 2 option in Python.

shutil

import shutil
shutil.copy(src, dst)

Robocopy with subprocess

import subprocess
command = "ROBOCOPY {} {} /MOVE /E".format(src, dst)
subprocess.Popen(command, shell=True)

When I used above methods my Python IDE do copy operation blindly.

Is there some way I can show the file copy progress.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

1 Answers1

2

If you are looking for the completed copy output, yes we can. Here is the code for that.

import subprocess
from subprocess import PIPE
cmd = r'ROBOCOPY {} {} {}'.format('D:\\TF1','D:\\TF2','license.xml')
p = subprocess.Popen(cmd,stderr=PIPE,stdout=PIPE)
a = p.communicate()
for i in a:
   print i

and the output will be as follows

  Started : Thu Jun 02 16:12:09 2016

   Source : D:\TF1\
   Dest : D:\TF2\

   Files : license.xml

  Options : /COPY:DAT /R:1000000 /W:30 

------------------------------------------------------------------------------

                   1    D:\TF1\

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         1         0         1         0         0         0
   Bytes :     1.7 k         0     1.7 k         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00

   Ended : Thu Jun 02 16:12:09 2016

Are you expecting something like this?
P.S: The actual output is much cleaner.

CiaPan
  • 9,381
  • 2
  • 21
  • 35
DineshKumar
  • 1,599
  • 2
  • 16
  • 30