Copy big files on Windows

A short Python script (from Activestate) to copy very big files on Windows:

import win32file

def copy_big_file(srcname, dstname):
        hin= win32file.CreateFile(
                srcname,
                win32file.GENERIC_READ,
                0, # win32file.FILE_SHARE_READ,
                None,
                win32file.OPEN_EXISTING,
                win32file.FILE_FLAG_SEQUENTIAL_SCAN,
                0)
##        print "type of hin=%r" % type(hin)
        hou= win32file.CreateFile(
                dstname,
                win32file.GENERIC_WRITE,
                0, # win32file.FILE_SHARE_READ,
                None,
                win32file.CREATE_ALWAYS,
                win32file.FILE_FLAG_SEQUENTIAL_SCAN,
                0)
        while 1:
                rc, buffer= win32file.ReadFile(hin, 65536)
                if not buffer: break
                if rc == 0:
                        win32file.WriteFile(hou, buffer)
                else:
                        print "rc=%d" % rc
                        break
        hin.Close()
        hou.Close()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.