ayu_2403 Posted June 6, 2023 Share Posted June 6, 2023 I want to copy a file from source to target and then note the time it took. But WinWaitClose function does not returns even if the copy is completed. What should i do #Include <WinAPIEx.au3> _WinAPI_ShellOpenFolderAndSelectItems('C:\Users\opc\Desktop\src\10GB_1.bin') Send("^c") WinClose("src") _WinAPI_ShellOpenFolderAndSelectItems('C:\Users\opc\Desktop\target') Send("{ENTER}") WinWaitActive("target","", 10) Send("^v") Local $sTitle = WinGetTitle("[CLASS:OperationStatusWindow]") ConsoleWrite($sTitle) Local $hTimer = TimerInit() WinWaitClose("[CLASS:OperationStatusWindow]") Local $fDiffInSec = TimerDiff($hTimer)/1000 ; ConsoleWrite($fDiffInSec&@CRLF) WinClose("target") Link to comment Share on other sites More sharing options...
water Posted June 6, 2023 Share Posted June 6, 2023 I would use the AutoIt commands FileCopy, TimerInit and TimerDiff. Any reason you are using this quite complex approach? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
ayu_2403 Posted June 6, 2023 Author Share Posted June 6, 2023 2 hours ago, water said: I would use the AutoIt commands FileCopy, TimerInit and TimerDiff. Any reason you are using this quite complex approach? I am using this approach because i have to make it user interactive. I have to show the user progress of copying file as shown by the Window that opens when you copy a file Link to comment Share on other sites More sharing options...
jguinch Posted June 6, 2023 Share Posted June 6, 2023 Here is one way : Local $hTimer = TimerInit() Local $sSource = "C:\Users\opc\Desktop\src\10GB_1.bin" Local $sDestination = "C:\Users\opc\Desktop\target\" _FileCopy($sSource, $sDestination) Local $fDiffInSec = TimerDiff($hTimer)/1000 Func _FileCopy($src, $dest) Local $oShell = ObjCreate("shell.application") $oShell.namespace($dest).CopyHere($src,256) EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Skeletor Posted June 6, 2023 Share Posted June 6, 2023 Here is one with a progress bar: #include <GUIConstantsEx.au3> #include <FileConstants.au3> Global $sourceFilePath = "C:\Temp\test.jar" Global $destinationFilePath = "C:\Temp\New folder\test_copy.jar" Example() Func Example() Local $hGUI, $hProgress, $hLabel, $fDiffInSec ; Create the GUI window $hGUI = GUICreate("File Copy Progress", 300, 120) $hProgress = GUICtrlCreateProgress(10, 10, 280, 20) $hLabel = GUICtrlCreateLabel("", 10, 40, 280, 20) GUISetState(@SW_SHOW, $hGUI) ; Perform the file copy Local $hTimer = TimerInit() If Not FileExists($destinationFilePath) Then FileCopy($sourceFilePath, $destinationFilePath, $FC_OVERWRITE) $fDiffInSec = TimerDiff($hTimer) / 1000 Else MsgBox(-1,"Replace","Replace the file?") EndIf ; Update progress bar and message bar GUICtrlSetData($hProgress, 100) GUICtrlSetData($hLabel, "File copy completed in " & $fDiffInSec & " seconds.") ; Wait for the user to close the GUI window While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete($hGUI) EndFunc Kind RegardsSkeletor "Coffee: my defense against going postal." Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI Link to comment Share on other sites More sharing options...
Solution ioa747 Posted June 6, 2023 Solution Share Posted June 6, 2023 2 hours ago, ayu_2403 said: But WinWaitClose function does not returns even if the copy is completed probably because the window is open, and the script is waiting to be closed #Include <WinAPIEx.au3> ConsoleWrite("WinExists=" & WinExists("[CLASS:OperationStatusWindow]") & @CRLF) _WinAPI_ShellOpenFolderAndSelectItems(@DesktopDir & '\src\10GB_1.bin') Send("^c") WinClose("src") _WinAPI_ShellOpenFolderAndSelectItems(@DesktopDir & '\target') Send("{ENTER}") $htarget = WinWaitActive("target","", 10) Send("^v") Local $sTitle = WinGetTitle($htarget) ConsoleWrite($sTitle & @CRLF) Local $hTimer = TimerInit() While Not FileExists(@DesktopDir & '\target\10GB_1.bin') Sleep(100) WEnd Local $fDiffInSec = TimerDiff($hTimer)/1000 ; ConsoleWrite($fDiffInSec & @CRLF) WinClose($htarget) PS: I agree FileCopy is more accurate I know that I know nothing Link to comment Share on other sites More sharing options...
ayu_2403 Posted June 7, 2023 Author Share Posted June 7, 2023 10 hours ago, ioa747 said: probably because the window is open, and the script is waiting to be closed #Include <WinAPIEx.au3> ConsoleWrite("WinExists=" & WinExists("[CLASS:OperationStatusWindow]") & @CRLF) _WinAPI_ShellOpenFolderAndSelectItems(@DesktopDir & '\src\10GB_1.bin') Send("^c") WinClose("src") _WinAPI_ShellOpenFolderAndSelectItems(@DesktopDir & '\target') Send("{ENTER}") $htarget = WinWaitActive("target","", 10) Send("^v") Local $sTitle = WinGetTitle($htarget) ConsoleWrite($sTitle & @CRLF) Local $hTimer = TimerInit() While Not FileExists(@DesktopDir & '\target\10GB_1.bin') Sleep(100) WEnd Local $fDiffInSec = TimerDiff($hTimer)/1000 ; ConsoleWrite($fDiffInSec & @CRLF) WinClose($htarget) PS: I agree FileCopy is more accurate I cannot use FileCopy because i have to show opening of folder and selecting a file and then copying it and then opening of destination and then pasting it. Also can someone tell me an alternative of _WinAPI_ShellOpenFolderAndSelectItems for opening a folder and then selecting a file from it because i have to show it Link to comment Share on other sites More sharing options...
water Posted June 7, 2023 Share Posted June 7, 2023 43 minutes ago, ayu_2403 said: Also can someone tell me an alternative of _WinAPI_ShellOpenFolderAndSelectItems for opening a folder and then selecting a file Please have a look at FileOpenDialog. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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