shutil.copyfile which has a default buffer size of 16384 bytes , as u kno copying wil take more time..
Below is the code that increases the buffer size as 10 MB.. u can copy files that are in Gbs..
import os
import shutil
def copyFile(src, dst, buffer_size=10485760, perserveFileDate=True):
# Check to make sure destination directory exists. If it doesn't create the directory
dstParent, dstFileName = os.path.split(dst)
if(not(os.path.exists(dstParent))):
os.makedirs(dstParent)
buffer_size = min(buffer_size,os.path.getsize(src))
if(buffer_size == 0):
buffer_size = 1024
if shutil._samefile(src, dst):
raise shutil.Error("`%s` and `%s` are the same file" % (src, dst))
for fn in [src, dst]:
try:
st = os.stat(fn)
except OSError:
# File most likely does not exist
pass
else:
# XXX What about other special files? (sockets, devices...)
if shutil.stat.S_ISFIFO(st.st_mode):
raise shutil.SpecialFileError("`%s` is a named pipe" % fn)
with open(src, 'rb') as fsrc:
with open(dst, 'wb') as fdst:
shutil.copyfileobj(fsrc, fdst, buffer_size)
if(perserveFileDate):
shutil.copystat(src, dst)
copyFile(r'D:\Reference Materials\Java_The_Complete_Reference,_7th_Edition.pdf',r'd:\2013\Java_The_Complete_Reference,_7th_Edition.pdf')