Jump to content

Recommended Posts

Posted

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")

 

Posted

I would use the AutoIt commands FileCopy, TimerInit and TimerDiff.
Any reason you are using this quite complex approach?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 6/6/2023 at 8:42 AM, water said:

I would use the AutoIt commands FileCopy, TimerInit and TimerDiff.
Any reason you are using this quite complex approach?

Expand  

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

Posted

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

 

Posted

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 Regards
Skeletor

"Coffee: my defense against going postal."

Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen | Full Screen UI

  • Solution
Posted
  On 6/6/2023 at 7:22 AM, ayu_2403 said:

But WinWaitClose function does not returns even if the copy is completed

Expand  

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

Posted
  On 6/6/2023 at 8:05 PM, 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

Expand  

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

Posted
  On 6/7/2023 at 6:20 AM, ayu_2403 said:

Also can someone tell me an alternative of _WinAPI_ShellOpenFolderAndSelectItems for opening a folder and then selecting a file

Expand  

Please have a look at FileOpenDialog.

My UDFs and Tutorials:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...