I wrote a script to transfer my files from internal hard drive to an external disk. Code:
import shutil
from shutil import copyfile
import glob
import os
from IPython import embed
import subprocess
path = os.getcwd()
#pathHD = glob.glob(path+"/HD*")
pathHD = glob.glob(path+"/RD*")
destPath = "/mnt/backUp2/data/"
for name in pathHD:
#embed()
baseName =os.path.basename(name)
#Checking if directory exists in dest path
if not (os.path.exists(destPath+baseName)):
print "Moving ",name,"--->",destPath
shutil.copytree(name,destPath+baseName) #recursive copying to destination dir
else:
print name," *****************Already exists**********"
I copying was superslow, so I did a ctrl-c to stop the process. But now, in my external hard disk, I am not able to find the moved files at all. I do not understand how ctrl-C should stop it because each shutil.copytree
command is independent of the other files.
My output:
Moving /home/dhiraj/RD 4992Aug12 ---> /mnt/backUp2/data/
Moving /home/raj/RD 4835Aug11 ---> /mnt/backUp2/data/
Moving /home/raj/RD 4329Aug02 ---> /mnt/backUp2/data/
Moving /home/raj/RD 4631Aug05 ---> /mnt/backUp2/data/
Moving /home/raj/RD 4049Jul31 ---> /mnt/backUp2/data/
Moving /home/raj/RD 4432Aug03 ---> /mnt/backUp2/data/
Moving /home/raj/RD 4011Jul31 ---> /mnt/backUp2/data/
Moving /home/raj/RD 4826Aug11 ---> /mnt/backUp2/data/
Moving /home/raj/RD 4732Aug05 ---> /mnt/backUp2/data/
^C^C^C^C^Z^Z^Z^Z^Z^Z^X^X^X^X^Z^Z^Z^Z^Z^Z^C^C^C
[1]+ Stopped python copy_files.py
My filesystem is NTFS and I unmounted(lazy) using sudo umount -l /dev/sdc2
. Whatever files that my output said, that it had moved, was not present in the destination file. Example, the first line of my output RD 4992Aug12 was notthere in my destination folder. I tested my script for a bunch of other files, which were also smaller in comparison and they worked fine. They were copies to my destination folder.
Please let me know if you can find why my copied files are missing
Should I use subprocess.Popen(cp) command instead?
NOTE: