# How to check whether a file copied completely?

## Recommended Posts

There is a build machine in the network where it will automatically download the code from source repository and compile using visual studio and compresses the complete code in a zip file.

I have added a line at the end of the build script(written in python on that machine) to copy that zip file to my ESX Virtual machine.

Where I kept a AutoIT exe to wait for the zip file, once it is copied then I will extract the contents and find only the dll files in the extracted folder and do the Install creation using Installshield silently and copy the created setup files to anther machine.

I wrote the script till the setup files creation.

But now the problem is, when the zip file is copying through network, the autoit script is detecting it even the copy is still in progress and trying to extract the zip file and failing.

Even when I am checking whether the file in use is not working.

Any suggestion on how to check whether the copy is completed.?

##### Share on other sites

FileGetSize to compare the size from thee network and the file on the machine. When they match the file is copied completely and can be extracted.

##### Share on other sites
14 minutes ago, InunoTaishou said:

FileGetSize to compare the size from thee network and the file on the machine. When they match the file is copied completely and can be extracted.

We can't access the server machine shared folders as they are restricted, only our machines can e accessed through server machine, so I am copying the file from there itself to my machine.

Is there anyway to check in our machine itself instead of accessing the server machine?

##### Share on other sites

How is your machine going to know everything is copied when it doesn't know big the file is supposed to be?

You could try adding another some more code on the machine sending the file to send to your machine that it's done when it's done copying. Open a TCP connection and send a finished value when it's done copying?

You could try

_WinAPI_FileInUse

It might return true if the file is being recognized as still downloading.

##### Share on other sites

One method that I have used, is to check the file size or modified time in a loop and when the value has not changed for a certain period of time, it should then be safe to assume that the download has completed.

Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

##### Share on other sites
On 11/20/2016 at 9:57 PM, Bowmore said:

One method that I have used, is to check the file size or modified time in a loop and when the value has not changed for a certain period of time, it should then be safe to assume that the download has completed.

Thanks Bowmore,I will try this approach.

If possible, can you please share that part of your code.

##### Share on other sites

You python script copies first the zip file, and then a 'token.txt' file... Your AutoIt script waits not for the zip, but instead for the txt file.

Logically, the txt can only be created/copied AFTER the zip file...

When the AutoIt script finds the txt, it now knows the zip must exist, deletes the txt (as a cleanup for the next cycle) and proceeds to process the zip...

This way everything will only start once the zip has been copied in full, without having the check Windows process etc.

-Skysnake

Skysnake

Why is the snake in the sky?

##### Share on other sites

This is the sort of thing I have used .

#include <FileConstants.au3>

Global $sFilepath = "P:\Users\Roy Kirby\Pictures\Africa 2002\01\2002-05_slide_02.tif" ;$stablefor  and $iTmeout values are in seconds ; use values appropriate for the time the file is expected to take to download or copy If CheckFileIsStable($sFilepath, 30, 300) Then
MsgBox(0, "CheckFile", $sFilepath & " - has been stable for at least 30 seconds so it has probably finished copying") Else MsgBox(0, "CheckFile",$sFilepath & " - has not been stable for at least 30 seconds in the last 5 minutes so it has probably stil copying")
EndIf

Func CheckFileIsStable($sFilepath,$stablefor = 60, $iTmeout = 1800) Local$sPrevFileTime = "A"
Local $sFileTime = "" Local$iPrevFileaize = -1
Local $iFilesize = 0 Local$bFileIsStable = False
Local $iTimeoutTimer = TimerInit() Do$iFilesize = FileGetSize($sFilepath) If @error = 0 Then$sFileTime = FileGetTime($sFilepath,$FT_MODIFIED, $FT_STRING) If @error = 0 Then If ($sPrevFileTime = $sFileTime) And ($iPrevFileaize = $iFilesize) Then ; File has not changed since last check$bFileIsStable = True
Else
$sPrevFileTime =$sFileTime
$iPrevFileaize =$iFilesize
Sleep($stablefor * 1000) EndIf EndIf EndIf Until$bFileIsStable Or TimerDiff($iTimeoutTimer) > ($iTmeout * 1000)

Return $bFileIsStable EndFunc ;==>CheckFileIsStable "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook ##### 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 • ### Recently Browsing 0 members No registered users viewing this page. • ### Similar Content • By t0nZ Always searching for the "final" solution to my zipping/unzipping needs, I started years ago using WinRar with AutoIT (don't ask me why...) and for the last 10 years I worked well with the _zip.UDF , a good solution using the embedded windows zipfldr.dll. But often I work with a lot of data (both multi gigabytes and/or 100K+ files) and I noticed the performance of the windows zip DLL are not so good, the problem is maybe worsened by the mono thread operation using AutoIT + zipfldr.dll. SO my choice is 7zip (7ZA.exe) also for licence (freeware also for business) reasons, and I wrote a small and simple UDF: ; #INDEX# ======================================================================================================================= ; Title .........: _7za ; AutoIt Version : 3.3.16.0 ; Language ......: English ; Description ...: Functions for using 7za.exe archive manipulation app ; Author(s) .....: NSC ; Version .......: 1.2 ; Date ..........: 2022/06/28 ; =============================================================================================================================== ; ------------------------------------------------------------------------------ ; This software is provided 'as-is', without any express or ; implied warranty. In no event will the authors be held liable for any ; damages arising from the use of this software. ; #INCLUDES# =================================================================================================================== ; #include-once #include <AutoItConstants.au3> ; =============================================================================================================================== ; #VARIABLES# =================================================================================================================== ; Global Global$7za_exe = @ScriptDir & "\" & "7za.exe" ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _EXEC7za ;_UNcompress_7za ;_COMpress_7za_7z ;_COMpress_7za_zip ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _EXEC7za ; Description ...: launch 7Za.exe with params and returns exit codes ; Syntax ........: EXEC7za($7zCommands,$archive, $folder[,$show]) ; Parameters ....: $7zCommands - 7zip command line params ;$archive - complete path to the archive ; $folder - the source/destination folder ;$show - optional set the state of 7za console visibility, default @SW_HIDE, ; other values as ShellExecuteWait() ; Return values .: 1 - Success ; 0 - and set @error = 1 ; and ; @extended = 1 (Warning (Non fatal error(s)) ; @extended = 2 (Fatal error) ; @extended = 7 (Command line error) ; @extended = 8 (Not enough memory for operation) ; @extended = 255 (User stopped the process) ; @extended values set by 7za.exe exit codes ; Author ........: NSC ; Modified ......: 2022/05/13 ; Remarks .......: requires 7za.exe in @scriptdir, 7za.exe (7-Zip Extra: standalone console version) ; Thanks to 7-zip.org ; Related .......: ; Link ..........: ; Examples .......: compress a folder recursive with subfolders ; EXEC7za("u -mx4 -bt", c:\folder1\archive.7z", c:\folder1\folderTOcompress\ ) ; uncompress the same folder recursive ; EXEC7za("x -aoa -bt -r", "c:\folder1\archive.7z", "-oc:\folder2\") ; =============================================================================================================================== Func _EXEC_7za($7zCommands,$archive, $folder,$show = @SW_HIDE) Local $return7za = ShellExecuteWait($7za_exe, $7zCommands & ' "' &$archive & '" "' & $folder & '"', '',$SHEX_OPEN, $show) Select Case$return7za = 0 Return 1 Case Else Return SetError(1, $return7za, 0) EndSelect EndFunc ;==>_EXEC_7za ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UNcompress_7za ; Description ...: launch 7Za.exe with preset params to uncompress an archive (.7z or .zip recursively) and returns exit codes ; Syntax ........: _UNcompress_7za($archive, $folder[,$show]) ; Parameters ....: $archive - complete path to the archive ;$folder - the source/destination folder ; $show - optional set the state of 7za console visibility, default @SW_HIDE, ; other values as ShellExecuteWait() ; Return values .: 1 - Success ; 0 - and set @error = 1 ; and ; @extended = 1 (Warning (Non fatal error(s)) ; @extended = 2 (Fatal error) ; @extended = 7 (Command line error) ; @extended = 8 (Not enough memory for operation) ; @extended = 255 (User stopped the process) ; @extended values set by 7za.exe exit codes ; Author ........: NSC ; Modified ......: 2022/05/19 ; Remarks .......: requires 7za.exe in @scriptdir, 7za.exe (7-Zip Extra: standalone console version) ; Thanks to 7-zip.org ; Related .......: ; Link ..........: ; =============================================================================================================================== Func _UNcompress_7za($archive, $folder,$show = @SW_HIDE) Local $return7za = ShellExecuteWait($7za_exe, "x -aoa -bt -r" & ' "' & $archive & '" -o"' &$folder & '"', '', $SHEX_OPEN,$show) Select Case $return7za = 0 Return 1 Case Else Return SetError(1,$return7za, 0) EndSelect EndFunc ;==>_UNcompress_Folder_7za ; #FUNCTION# ==================================================================================================================== ; Name ..........: _COMpress_7za_7z ; Description ...: launch 7Za.exe with precompiled params to compress in .7z format ;a single file, a filtered (*.pdf) bunch of files or a folder (recursively) and returns exit codes ; Syntax ........: _COMpress_7za_7z($archive,$folder[, $show [,$compLvl]] ) ; Parameters ....: $archive - complete path to the archive ;$folder - the source file(s) / folder ; $show - optional set the state of 7za console visibility, default @SW_HIDE, ; other values as ShellExecuteWait() ;$CompLvl - optional compression level (1-9) default 4 ; Return values .: 1 - Success ; 0 - and set @error = 1 ; and ; @extended = 1 (Warning (Non fatal error(s)) ; @extended = 2 (Fatal error) ; @extended = 7 (Command line error) ; @extended = 8 (Not enough memory for operation) ; @extended = 255 (User stopped the process) ; @extended values set by 7za.exe exit codes ; Author ........: NSC ; Modified ......: 2022/06/22 ; Remarks .......: requires 7za.exe in @scriptdir, 7za.exe (7-Zip Extra: standalone console version) ; avoids re-compress of popular archives. ; Thanks to 7-zip.org ; Related .......: ; Link ..........: ; =============================================================================================================================== Func _COMpress_7za_7z($archive,$folder, $show = @SW_HIDE,$CompLvl = 4) If StringRight($folder, 4) = ".zip" Or StringRight($folder, 3) = ".7z" Or StringRight($folder, 4) = ".rar" Or StringRight($folder, 4) = ".lha" Or StringRight($folder, 3) = ".gz" Or StringRight($folder, 7) = ".tar.gz" Or StringRight($folder, 4) = ".iso" Then$CompLvl = 0 EndIf Local $return7za = ShellExecuteWait($7za_exe, 'u -mx' & $CompLvl & ' -mmt -bt' & ' "' &$archive & '" "' & $folder & '"', '',$SHEX_OPEN, $show) Select Case$return7za = 0 Return 1 Case Else Return SetError(1, $return7za, 0) EndSelect EndFunc ;==>_COMpress_7za_7z ; #FUNCTION# ==================================================================================================================== ; Name ..........: _COMpress_7za_zip ; Description ...: launch 7Za.exe with precompiled params to compress in zip format ; a single file, a filtered (*.pdf) bunch of files or a folder (recursively) and returns exit codes ; Syntax ........: _COMpress_7za_zip($archive, $folder[,$show [, $compLvl]] ) ; Parameters ....:$archive - complete path to the archive ; $folder - the source file(s) / folder ;$show - optional set the state of 7za console visibility, default @SW_HIDE, ; other values as ShellExecuteWait() ; $CompLvl - optional compression level (1-9) default 4 ; Return values .: 1 - Success ; 0 - and set @error = 1 ; and ; @extended = 1 (Warning (Non fatal error(s)) ; @extended = 2 (Fatal error) ; @extended = 7 (Command line error) ; @extended = 8 (Not enough memory for operation) ; @extended = 255 (User stopped the process) ; @extended values set by 7za.exe exit codes ; Author ........: NSC ; Modified ......: 2022/06/22 ; Remarks .......: requires 7za.exe in @scriptdir, 7za.exe (7-Zip Extra: standalone console version), ; avoids re-compress of popular archives. ; Thanks to 7-zip.org ; Related .......: ; Link ..........: ; =============================================================================================================================== Func _COMpress_7za_zip($archive, $folder,$show = @SW_HIDE, $CompLvl = 9) If StringRight($folder, 4) = ".zip" Or StringRight($folder, 3) = ".7z" Or StringRight($folder, 4) = ".rar" Or StringRight($folder, 4) = ".lha" Or StringRight($folder, 3) = ".gz" Or StringRight($folder, 7) = ".tar.gz" Or StringRight($folder, 4) = ".iso" Then $CompLvl = 0 EndIf Local$return7za = ShellExecuteWait($7za_exe, 'u -tzip -mx' &$CompLvl & ' -mmt -bt' & ' "' & $archive & '" "' &$folder & '"', '', $SHEX_OPEN,$show) Select Case $return7za = 0 Return 1 Case Else Return SetError(1,$return7za, 0) EndSelect EndFunc ;==>_COMpress_7za_zip You have to provide 7za.exe, in scriptdir in some way, maybe with a fileinstall or embedding in some way.
Daily I use most of the time:
_UNcompress_7za
_COMpress_7za_7z
so I'am almost done with these funcs....
Also I made a quick and dirty benchmark on some real world data (for me at least) , comparing the windows DLL, the zip ULTRA by 7zip and the various 7zip levels.

My choice is level 4 (time/size) but your mileage may vary...
Also, extracting many thousands of little files from a 7z archive with 7zip is waaaay fast in respect to other solutions.
• By DevMode
welcome
I need help dealing with a C++ DLL
Specify that I need help with how to use this function
struct libusb_device; typedef struct libusb_context libusb_context; ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,libusb_device ***list); My problem is how to deal with "libusb_device ***list"
my code
$libusb_device = DllStructCreate("PTR") Func libusb_init()$Var = DllCall($libusb0, "ptr", "libusb_init",'ptr',$_libusb_device_handle_Ptr) If @error Then Return False Return $Var[1] EndFunc Func libusb_get_device_list() MsgBox(0,VarGetType($_libusb_device_handle_Ptr),$_libusb_device_handle_Ptr)$Var = DllCall($libusb0, "int", "libusb_get_device_list","ptr",$_libusb_device_handle_Ptr,"ptr*",POINTER(POINTER($libusb_device)))$Error = @error If $Error Then Return False MsgBox(0,VarGetType($Var),$Error&@CRLF&$Var) _ArrayDisplay($Var) Return$Var[1] EndFunc
Thank you
iLibUSB.dll iLibUSB_32.dll libusb.h
• By vinnyMS
#Include <Array.au3> #include <Constants.au3> $s = FileRead("2.txt") Local$w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3) _ArrayColInsert($w, 1) For $i = 0 to UBound($w)-1 StringRegExpReplace($s, '(?i)\b' &$w[$i][0] & '\b',$w[$i][0])$w[$i][1] = @extended Next _ArraySort($w, 1, 0, 0, 1) _ArrayDisplay($w) i have this script that returns 3 columns i need to copy the Col 0 and Col 1 as text to paste on notepad or excel you will have to create a "copy" button if possible array.au3 2.txt • Hi all, My programming knowledge is very basic. I have an old script that creates shares and assign permissions. It normally registers SetAcl.ocx if necessary and creates an object to assign permissions. The command that registers SetAcl was apparently working fine under Windows 7 but is not working under Windows 10. RunWait("regsvr32.exe path\to\setacl.ocx /s", "", @SW_HIDE) As I'm logged in as admin, I changed this command to : RunAsWait(@UserName, "", "", 0, "regsvr32.exe path\to\setacl.ocx /s", "", @SW_HIDE) It seems to terminate correctly but the script still doesn't work as expected. To check that, I've created that small script : Local$objSetAcl = ObjCreate("SETACL.SetACLCtrl.1") If IsObj($objSetAcl) Then ConsoleWrite("Object successfully created." & @CRLF) Else ConsoleWrite("Object not created. Registering SetAcl.ocx" & @CRLF) Local$result = RunAsWait(@UserName, "", "", 0, "regsvr32.exe path\to\setacl.ocx /s", "", @SW_HIDE); Use of my admin username to elevate CMD ConsoleWrite("Return code : " & $result & @CRLF) ConsoleWrite("Creating object" & @CRLF)$objSetAcl = ObjCreate("SETACL.SetACLCtrl.1") If IsObj(\$objSetAcl) Then ConsoleWrite("Object successfully created." & @CRLF) Else ConsoleWrite("Object creation failed." & @CRLF) EndIf EndIf It tries to register SetAcl.ocx, return code 0 seems to be fine but still can't use SetAcl.
But if I go to CMD as admin, run the regsvr32 command and restart my script, it can create the object without issue.
I know my poor knowledge makes me miss something. Anyone can help me figure this out ?

• Dear members of the forum,
I'm working on a project in which I have to use Image recognition technique.
Due to client restrictions, I couldn't use AutoIt for this project.
Is there a way to use this DLL "ImageSearchDLL.dll" (which is used to do image recognition steps in AutoIt) in VB.Net to achieve the same result?
I have used this DLL few years before and got good results. If there is a latest version of this DLL and if you can share it, that will be helpful too.
Any guidance is deeply appreciated.
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...