Jump to content
Sign in to follow this  
Dtvscrotes

FileCopy with Progress

Recommended Posts

Dtvscrotes

I am moving 700mb .avi video files with FileMove.

Currently that part of my script goes

msgbox says please wait for a msg filemove complete

Filemove - moves the avi

Msgbox File Move Complete.

It takes around 15 - 20 seconds for the second popup to occur. Is there any way to use a progressbar to track

how long it will take to move the avi file? Like when you copy paste files in windows it shows the progress bar.

Share this post


Link to post
Share on other sites
Yashied

Method 1.

#Include <Misc.au3>
#Include <WinAPIEx.au3>

Global $hProgressRoutine = DllCallbackRegister('_Progress', 'int', 'uint64;uint64;uint64;uint64;dword;dword;ptr;ptr;ptr')

_WinAPI_CopyFileEx('D:\Test.tmp', 'C:\Test.tmp', DllCallBackGetPtr($hProgressRoutine), $COPY_FILE_FAIL_IF_EXISTS)
MsgBox(0, 'CopyFileEx', _WinAPI_GetLastErrorMessage())
DllCallbackFree($hProgressRoutine)

Func _Progress($iTotalFileSize, $iTotalBytesTransferred, $iStreamSize, $iStreamBytesTransferred, $iStreamNumber, $iCallbackReason, $hSourceFile, $hDestinationFile, $iData)
    ConsoleWrite(Round($iTotalBytesTransferred / $iTotalFileSize * 100, 1) & '%' & @CR)
    If _IsPressed('1B') Then
        Return $PROGRESS_CANCEL
    Else
        Return $PROGRESS_CONTINUE
    EndIf
EndFunc   ;==>_Progress

WinAPIEx.au3

Method 2.

; Windows - copy with progress
; Author - JdeB

;~ 4 Do not display a progress dialog box.  
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.  
;~ 16 Respond with "Yes to All" for any dialog box that is displayed.  
;~ 64 Preserve undo information, if possible.
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified.  
;~ 256 Display a progress dialog box but do not show the file names.  
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created.  
;~ 1024 Do not display a user interface if an error occurs.  
;~ 2048 Version 4.71. Do not copy the security attributes of the file.
;~ 4096 Only operate in the local directory. Don't operate recursively into subdirectories.
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files.  

_FileCopy("D:\test.tmp","C:\")

Func _FileCopy($fromFile,$tofile)
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)
EndFunc

Share this post


Link to post
Share on other sites
Dtvscrotes

Thanks Yashied. Method 2 worked perfect for me. I may try method 1 later and see what I like better even though method 2 was perfect.

Share this post


Link to post
Share on other sites
VAN0

Hello.

Thank you for the code.

Method 1 works good for small files, but on large files it freezes gui until finished.

Is there a way use method 2 with multiple files so it would show only one window until finished copying all files?

Thanks

Share this post


Link to post
Share on other sites
FreeBeing

Thank you for your code Yashied, it really help me ;)

PS : I appreciate Method 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×