thexshadow Posted February 28, 2010 Share Posted February 28, 2010 I have been looking around for a file copy with progress bar script, and I found it Here. Now, I have been playing around with it, but I cannot think of a way to link a button to start the file copy, instead of it automatically starting.Would anyone have any ideas? Link to comment Share on other sites More sharing options...
dani Posted February 28, 2010 Share Posted February 28, 2010 Be sure to check the example on the GUICtrlCreateButton reference page. If you use OnEvent mode (which I always prefer), you can use GUICtrlSetOnEvent.This should get you going in the right - and easy - direction Link to comment Share on other sites More sharing options...
thexshadow Posted February 28, 2010 Author Share Posted February 28, 2010 (edited) I already knew about GUICtrlCreateButto, GUICtrlSetOnEvent looks like it will be perfect.Thanks!One problem I am having is when I run my script, the file transfer starts automatically. Would there be any way to stop it from running auto?I have tried a few things. My latest try.expandcollapse popup#include <GuiConstantsEx.au3> Opt("GuiOnEventMode", 1) $hGUI = GUICreate("Test", 300, 300) GUICtrlCreateButton("test", 100, 100, 100, 30) GUICtrlSetOnEvent(-1, "_CopyWithProgress") GUISetState() Files Files Files _CopyWithProgress() If $FileCopy = 0 Then MsgBox(0,"Copy Complete", "File Copy Successful.") Else MsgBox(16,"Copy Complete", "File Copy Failed.") EndIf Func _CopyWithProgress($inSource, $inDest, $ChunkSize = 2048) $SourceFile = FileOpen($inSource, 16) ; Check that file open was successful If $SourceFile = -1 Then MsgBox(16, "Error", "Unable to open source file: " & $inSource) Exit EndIf ; Open destination file for BINARY writing , overwriting existing file and creating directory structure if it doesn't exist $DestFile = FileOpen($inDest, 26) ; Check that file open was successful If $SourceFile = -1 Then MsgBox(16, "Error", "Unable to open destination file: " & $inDest) Exit EndIf ; Get the size of the file we are going to copy $SourceSize = FileGetSize($inSource) ; Calculate how many chunks we need to copy $Chunks = $SourceSize / $ChunkSize ; Show the progress bar ProgressOn("File Copy", "Copying...", "Source: " & $inSource & @LF & "Dest: " & $inDest) ; Loop from 0 to number of chunks For $i = 0 to $Chunks ; Read the next chunk $Data = FileRead($SourceFile, $ChunkSize) ; Write the next chunk FileWrite($DestFile, $Data) ; Update the progress bar ProgressSet( (($i + 1) / $Chunks) * 100 ) Next ; Hide the progress bar ProgressOff() ; Close the source file FileClose($SourceFile) ; Close the destination file FileClose($DestFile) ; Check the file copy was successful $DestSize = FileGetSize($inDest) If $SourceSize = $DestSize Then Return 0 Else Return 1 EndIf EndFuncIt starts the transfer when the app starts. I have also tried it with While 1. Same thing. Any ideas? Edited February 28, 2010 by thexshadow Link to comment Share on other sites More sharing options...
playlet Posted February 28, 2010 Share Posted February 28, 2010 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
somdcomputerguy Posted February 28, 2010 Share Posted February 28, 2010 Change Files _CopyWithProgress() If $FileCopy = 0 Then to Files ;_CopyWithProgress() If $FileCopy = 0 Then - Bruce /*somdcomputerguy */Â If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
thexshadow Posted February 28, 2010 Author Share Posted February 28, 2010 (edited) @playletNot exactly what I wanted. But I think I can work with it. I wanted files from the autoit script to be copied.$FileCopy = FileCopy("Extract\AudMgr_AM_ible.dll", "Test\AudioPluginMgr\AM_ible.dll") $FileCopy = FileCopy("Extract\AudnMgr_AM_PP.dll", "Test\AudioPluginMgr\AM_PP.dll")Now, I just need to figure out a way to do that. Edited February 28, 2010 by thexshadow Link to comment Share on other sites More sharing options...
BrettF Posted February 28, 2010 Share Posted February 28, 2010 FileInstall? :S Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
thexshadow Posted February 28, 2010 Author Share Posted February 28, 2010 Well, I don't mean actually packed into the exe. I mean copy files from one folder to another (not the entire folder). Link to comment Share on other sites More sharing options...
thexshadow Posted March 2, 2010 Author Share Posted March 2, 2010 Well, tried editing it. It kind of reverted back to its original workings.expandcollapse popupGlobal $DestFile Global $SourceFile ;Files To Copy _CopyWithProgress("Extract\AudMgr_AM_ible.dll", "Test\AudioPluginMgr\AM_ible.dll") _CopyWithProgress("Extract\AudnMgr_AM_PP.dll", "Test\AudioPluginMgr\AM_PP.dll") ;End $hGUI = GUICreate("Test", 300, 300) $button = GUICtrlCreateButton("test", 100, 100, 100, 30) GUISetState() While 1 Switch GUIGetMsg() Case $button $FileCopy = _CopyWithProgress($SourceFile, $DestFile) If $FileCopy = 1 Then MsgBox(0,"Copy Complete", "File Copy Successful.") Else MsgBox(16,"Copy Complete", "File Copy Failed.") EndIf Case -3; This is actually $GUI_EVENT_CLOSE Exit EndSwitch Sleep(10) WEnd Func _CopyWithProgress($SourceFile, $DestFile) If $SourceFile = -1 Then; Check that file open was successful MsgBox(16, "Error", "Unable to open source file: " & $copy_what) Return 0; THIS ENDS FUNCTION HERE AND SAYS THAT THERE WAS AN ERROR - YOU CAN TRY AGAIN WITH NEW SETTINGS EndIf $getfiletype = StringSplit ($SourceFile, ".", 1) $extension = $getfiletype[$getfiletype[0]] $DestFile = FileOpen($DestFile & "." & $extension, 26); Open destination file for BINARY writing , overwriting existing file and creating directory structure if it doesn't exist If $SourceFile = -1 Then; Check that file open was successful MsgBox(16, "Error", "Unable to open destination file: " & $DestFile) Return 0; THIS ENDS FUNCTION HERE AND SAYS THAT THERE WAS AN ERROR - YOU CAN TRY AGAIN WITH NEW SETTINGS EndIf $SourceSize = FileGetSize($SourceFile); Get the size of the file we are going to copy $Chunks = $SourceSize / 2048; Calculate how many chunks we need to copy ProgressOn("File Copy", "Copying...", "Source: " & $SourceFile & @LF & "Dest: " & $DestFile); Show the progress bar For $i = 0 to $Chunks; Loop from 0 to number of chunks $Data = FileRead($SourceFile, 2048); Read the next chunk FileWrite($DestFile, $Data); Write the next chunk ProgressSet(($i / $Chunks) * 100); Update the progress bar Next FileClose($DestFile); Close the destination file FileClose($SourceFile); Close the source file ProgressOff(); Hide the progress bar If FileGetSize($DestFile & "." & $extension) = $SourceSize Then Return 1; Check the file copy was successful Return 0 EndFunc Link to comment Share on other sites More sharing options...
playlet Posted March 2, 2010 Share Posted March 2, 2010 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
thexshadow Posted March 3, 2010 Author Share Posted March 3, 2010 Thanks playlet, looks like that is exactly what I want. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now