CopyFileEx.py 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import win32file, win32api
  2. import os
  3. def ProgressRoutine(TotalFileSize, TotalBytesTransferred, StreamSize, StreamBytesTransferred,
  4. StreamNumber, CallbackReason, SourceFile, DestinationFile, Data):
  5. print(Data)
  6. print(TotalFileSize, TotalBytesTransferred, StreamSize, StreamBytesTransferred, StreamNumber, CallbackReason, SourceFile, DestinationFile)
  7. ##if TotalBytesTransferred > 100000:
  8. ## return win32file.PROGRESS_STOP
  9. return win32file.PROGRESS_CONTINUE
  10. temp_dir=win32api.GetTempPath()
  11. fsrc=win32api.GetTempFileName(temp_dir,'cfe')[0]
  12. fdst=win32api.GetTempFileName(temp_dir,'cfe')[0]
  13. print(fsrc, fdst)
  14. f=open(fsrc,'w')
  15. f.write('xxxxxxxxxxxxxxxx\n'*32768)
  16. f.close()
  17. ## add a couple of extra data streams
  18. f=open(fsrc+':stream_y','w')
  19. f.write('yyyyyyyyyyyyyyyy\n'*32768)
  20. f.close()
  21. f=open(fsrc+':stream_z','w')
  22. f.write('zzzzzzzzzzzzzzzz\n'*32768)
  23. f.close()
  24. operation_desc='Copying '+fsrc+' to '+fdst
  25. win32file.CopyFileEx(fsrc, fdst, ProgressRoutine, Data=operation_desc, Cancel=False, CopyFlags=win32file.COPY_FILE_RESTARTABLE, Transaction=None)