ur

How to check whether a file copied completely?

8 posts in this topic

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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 this post


Link to post
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 this post


Link to post
Share on other sites

How about this?

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 this post


Link to post
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

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

  • Similar Content

    • mjolnirmarkiv
      By mjolnirmarkiv
      Hi!
      Is there any way to use .NET DLL libraries with AutoIt? I happen to have one that'd have made my life easier, but DLLCall() returns an error: no functions with such name found. Searching and reading forums made me think that's not a fault of a library. I've used yashied's DLL Helper, but it didn't return any function names as well.
      Thanks!
    • vindicta
      By vindicta
      Hello Everyone,
      Please pardon my noobiness. I am working on backup restore script where a progress bar is required. I have tried using following code which works fine with folders but not really with single file because robocopy
      Func CopyFolder($srcDir, $destDir, $part) ;======> $part shows whats being copied (e.g. Desktop, Documents etc.) If StringRight($srcDir, 1) = "\" Then $srcDir = StringLeft($srcDir, StringLen($srcDir) - 1) If Not FileExists($destDir) Then DirCreate($destDir) $srcSize = DirGetSize($srcDir, $DIR_EXTENDED) $1_percent = $srcSize[0] / 100 $cmd = 'C:\Windows\System32\robocopy.exe "' & $srcDir & '" "' & $destDir & '" /E /Z /XO /XX /FFT /XJ /NDL /NJH /FP /ETA /NP /V /R:10 /W:5 /LOG+:"' & $logFile & '" /XF desktop.ini thumbs.db' Run(@ComSpec & " /c " & $cmd, "", @SW_HIDE) Do Sleep(300) Until ProcessExists("robocopy.exe") ProgressOn($part, $1_percent & "%", "", 0, 0, 16) Do $destSize = DirGetSize($destDir, $DIR_EXTENDED) ProgressSet(Round($destSize[0] / $1_percent, 2), Round($destSize[0] / (1024 * 1024), 2) & " MB of " & Round($srcSize[0] / (1024 * 1024), 2) & " MB copied", Round($destSize[0] / $1_percent, 2) & "%") Sleep(200) Until ProcessExists("robocopy.exe") = 0 ProgressOff() FileWriteLine($logFile, @CRLF & @CRLF) EndFunc ;==>CopyFolder Part of the problem is that I need to generate logs of files being copied. One particular problem is firefox profile directory. the directory is named as oi3jdslk.default or asdwdx.new and I need to copy places.sqlite from this directory.
      Xcopy manages to copy FROM this directory but not TO this directory because of wildcards
      Then I came across this neat script 
      Func CopyFile($fromFile, $todirectory) Local $FOF_RESPOND_YES = 16 Local $FOF_SIMPLEPROGRESS = 256 $winShell = ObjCreate("shell.application") $winShell.namespace($todirectory).CopyHere($fromFile, $FOF_RESPOND_YES) EndFunc ;==>CopyFile It helped me copy other single files but not the one required from firefox profile folder. Here is how I am trying to process that
      $path = @UserProfileDir & "\AppData\Roaming\Mozilla\Firefox\" & $ffDir & "\places.sqlite" CopyFile($path, $BUFolder & "Mozilla") ;===> $BUFolder = "E:\" & @username & " - Backup\" #cs ====================================================== $ffDir is another variable derived from this function. This variable is the gets the default firefox profile to copy places.sqlite from $ffDir is returned as Profiles\xbsen2s.default (Firefox randomizes the profile directory for extra security(?). At least that's what they say. #ce ====================================================== Func FFProfile() Local $iniFile = @UserProfileDir & "\AppData\Roaming\Mozilla\Firefox\profiles.ini" Local $ddNumber Local $ddLine Local $Line If FileExists($iniFile) Then FileOpen($iniFile, 0) For $i = 1 To _FileCountLines($iniFile) $Line = FileReadLine($iniFile, $i) If StringInStr("DEFAULT=1", $Line) Then $ddNumber = $i - 1 ExitLoop ElseIf StringInStr("Name=default", $Line) Then $ddNumber = $i + 2 EndIf Next $ddLine = FileReadLine($iniFile, $ddNumber) $ffDir = StringReplace(StringTrimLeft($ddLine, 5), "/", "\") $ffInstall = 1 Else $ffInstall = 0 EndIf FileClose($iniFile) EndFunc ;==>FFProfile I really like how natural the progress bar from second copy script look like and would like to keep the progress bar uniform across the program. I am willing to learn if anyone can point me in right direction and help me achieve this.

      Any help is highly appreciated!!
    • BisherSH
      By BisherSH
      Good day ,
      I have the code below , and i would like to embed SQLite3.dll to the compiled file 
      Is it possible ? 
      Thanks in advance
      #include <SQLite.au3> #include <SQLite.dll.au3> _SQLite_Startup() If @error Then     MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!")     Exit -1 EndIf $DB = _SQLite_Open("C:\Temp\Test.db") $Action = "TestAction" $Time = @HOUR&":"&@MIN&":"&@SEC $Date = @YEAR&"-"&@MON&"-"&@MDAY $User = @UserName $Computer = @ComputerName $DC = @LogonServer If @error Then     MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Couldnt open Database")     Exit -1 EndIf _SQLite_Exec($DB,"INSERT INTO QLogs (Action,Date,Time,User,Computer,DC) " & _                               "VALUES ("& _SQLite_FastEscape($Action) & "," & _                                           _SQLite_FastEscape($Date) & "," & _                                           _SQLite_FastEscape($Time) & "," & _                                           _SQLite_FastEscape($User) & "," & _                                           _SQLite_FastEscape($Computer) & "," & _                                           _SQLite_FastEscape($DC) & ");") If @error Then     MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Couldnt insert!")     Exit -1 EndIf _SQLite_Shutdown()
    • ur
      By ur
      I got a UDF to zip the files from below link.
      With this I am able to create a zip file but the post processing of zip file creation I am checking the zip file exists or not, but it is giving the message as file not found.
       
      Any sugestions??
      #include "Zip.au3" ZipLogs() Func ZipLogs() $ResultsFolder = @ScriptDir & "\Results" $ResultsDestFolder = @ScriptDir & "\Results_Archive" $zipFile = $ResultsDestFolder & "\Results_"&TodayDateTime()&".zip" DirCreate($ResultsDestFolder) Dim $Zip = _Zip_Create($zipFile) ;Create The Zip File. Returns a Handle to the zip File _Zip_AddFolderContents($Zip, $ResultsFolder) ;Add a folder's content in the zip file if FileExists(@ScriptDir&"\Logging.log") then _Zip_AddFile($Zip,@ScriptDir&"\Logging.log") FileDelete(@ScriptDir&"\Logging.log") EndIf if FileExists(@ScriptDir&"\RemoteExecution_Log.txt") then _Zip_AddFile($Zip,@ScriptDir&"\RemoteExecution_Log.txt") FileDelete(@ScriptDir&"\RemoteExecution_Log.txt") EndIf if FileExists($zipFile) then DirRemove($ResultsFolder,$DIR_REMOVE) Else MsgBox(0,"","Zip file not found") EndIf return $zipFile EndFunc  
      Zip.au3
    • likehu
      By likehu
      Hello,
      I have compiled a reference DLL in VS 2015 Community and this  DLL works fine with project for which it is used. There is an interface from which u can access functions in DLL.
      Developers stated that this DLL is almost universal and can be used with any language with minor changes.
      I am trying to access its function from Autoit script and got an error 3, after calling DLLCall - "function" not found in the DLL file.
      Please have a quick look, I feel I miss something in C++ library with exporting functions and I do not know what to add as I am new to C++.
      Thank you.
      Source files and script also attached.
       
      Here is my script.
      Local $dll = DllOpen("C:\Users\Home\Desktop\dll\user.dll") ConsoleWrite("$dll handle = " & $dll & @CRLF) ;$dll handle = 1 Local $result = DllCall($dll, "double:cdecl", "ProcessQuery", "str", "dll$mynumber") If @error > 0 Then ConsoleWrite("Error: " & @error & @CRLF) ;Error = 3 If IsArray($result) Then ConsoleWrite("Array returned!" & @CRLF & "dll$mynumber: " & result[1]) Else ConsoleWrite("$result is not array. : " & $result & @CRLF) ;$result = 0 EndIf DllClose($dll) And here is dll source. As I understand, function "ProcessQuery" exported with help of DLL_IMPLEMENTS
      user.h
      //****************************************************************************** // // This file is part of the OpenHoldem project // Download page: http://code.google.com/p/openholdembot/ // Forums: http://www.maxinmontreal.com/forums/index.php // Licensed under GPL v3: http://www.gnu.org/licenses/gpl.html // //****************************************************************************** // // Purpose: Very simple user-DLL as a starting-point // // DO NOT CHANGE ANYTHING IN THIS FILE! // // This Header defines an interface // Functions and data-types must exactly match. // //****************************************************************************** #ifndef _INC_USER_H #define _INC_USER_H // Import and export directives // for use by this DLL and by OpenHoldem #ifdef USER_DLL #define DLL_IMPLEMENTS extern "C" __declspec(dllexport) #define EXE_IMPLEMENTS extern "C" __declspec(dllimport) #else #define DLL_IMPLEMENTS extern "C" __declspec(dllimport) #define EXE_IMPLEMENTS extern "C" __declspec(dllexport) #endif // Number of saved table-states // This number must not be changed, as we do a "& 0xFF" // at various places to normalize the index. const int kNumberOfHoldemStatesForDLL = 256; // SHoldemePlayer // used for sequence of 256 consequive table-states // !!!! Needs 2 more cards for Omaha, if not entirely removed struct holdem_player { char m_name[16] ; //player name if known double m_balance ; //player balance double m_currentbet ; //player current bet unsigned char m_cards[2] ; //player cards unsigned char m_name_known : 1 ; //0=no 1=yes unsigned char m_balance_known : 1 ; //0=no 1=yes unsigned char m_fillerbits : 6 ; //filler bits unsigned char m_fillerbyte ; //filler bytes }; struct holdem_state { char m_title[64] ; //table title double m_pot[10] ; //total in each pot unsigned char m_cards[5] ; //common cards unsigned char m_is_playing : 1 ; //0=sitting-out, 1=sitting-in unsigned char m_is_posting : 1 ; //0=autopost-off, 1=autopost-on unsigned char m_fillerbits : 6 ; //filler bits unsigned char m_fillerbyte ; //filler byte unsigned char m_dealer_chair ; //0-9 holdem_player m_player[10] ; //player records }; // Functions implemented and exported by the DLL, // imported by OpenHoldem DLL_IMPLEMENTS double __stdcall ProcessQuery(const char* pquery); DLL_IMPLEMENTS void __stdcall DLLOnLoad(); DLL_IMPLEMENTS void __stdcall DLLOnUnLoad(); // Functions implemented and exported by OpenHoldem, // imported by the DLL EXE_IMPLEMENTS double __stdcall GetSymbol(const char* name_of_single_symbol__not_expression); EXE_IMPLEMENTS void* __stdcall GetPrw1326(); EXE_IMPLEMENTS char* __stdcall GetHandnumber(); EXE_IMPLEMENTS void __stdcall ParseHandList(const char* name_of_list, const char* list_body); EXE_IMPLEMENTS char* __stdcall ScrapeTableMapRegion(char* p_region, int& p_returned_lengh); EXE_IMPLEMENTS void __stdcall SendChatMessage(const char *message); EXE_IMPLEMENTS void __stdcall WriteLog(char* format, ...); // Variables exported by OpenHoldem // avoiding the message-mess of WinHoldem, // no longer sending any state-messages // http://www.maxinmontreal.com/forums/viewtopic.php?f=174&t=18642 EXE_IMPLEMENTS extern holdem_state state[kNumberOfHoldemStatesForDLL]; EXE_IMPLEMENTS extern int state_index; #endif // _INC_USER_H  
      user.cpp    Here is dll$mynumber parameter.
      //****************************************************************************** // // This file is part of the OpenHoldem project // Download page: http://code.google.com/p/openholdembot/ // Forums: http://www.maxinmontreal.com/forums/index.php // Licensed under GPL v3: http://www.gnu.org/licenses/gpl.html // //****************************************************************************** // // Purpose: Very simple user-DLL as a starting-point // // Required OpenHoldem version: 7.7.6 // //****************************************************************************** // Needs to be defined here, before #include "user.h" // to generate proper export- and inport-definitions #define USER_DLL // #define OPT_DEMO_OUTPUT if you are a beginner // who wants to see some message-boxes with output of game-states, etc. // It is disabled upon request, // * as it is not really needed // * as some DLL-users don't have MFC (atlstr.h) installed // http://www.maxinmontreal.com/forums/viewtopic.php?f=156&t=16232 #undef OPT_DEMO_OUTPUT #include "user.h" #include <conio.h> #include <windows.h> #ifdef OPT_DEMO_OUTPUT #include <atlstr.h> #endif OPT_DEMO_OUTPUT // Supporting macros #define HIGH_NIBBLE(c) (((c)>>4)&0x0F) #define LOW_NIBBLE(c) ((c)&0x0F) // Card macro #define RANK(c) ( ISKNOWN(c) ? HIGH_NIBBLE(c) : 0 ) #define SUIT(c) ( ISKNOWN(c) ? LOW_NIBBLE(c) : 0 ) #define ISCARDBACK(c) ((c) == CARD_BACK) #define ISUNKNOWN(c) ((c) == CARD_UNDEFINED) #define ISNOCARD(c) ((c) == CARD_NOCARD) #define ISKNOWN(c) (!ISCARDBACK(c) && !ISUNKNOWN(c) && !ISNOCARD(c)) // ProcessQuery() // Handling the lookup of dll$symbols DLL_IMPLEMENTS double __stdcall ProcessQuery(const char* pquery) { if (pquery==NULL) return 0; if (strncmp(pquery,"dll$mynumber",13)==0) { return 12345.67; } return 0; } // OnLoad and OnUnload() // called once and at the beginning of a session // when the DLL gets loaded / unloaded // Do initilization / finalization here. DLL_IMPLEMENTS void __stdcall DLLOnLoad() { #ifdef OPT_DEMO_OUTPUT MessageBox(NULL, "event-load", "MESSAGE", MB_OK); #endif OPT_DEMO_OUTPUT } DLL_IMPLEMENTS void __stdcall DLLOnUnLoad() { #ifdef OPT_DEMO_OUTPUT MessageBox(NULL, "event-unload", "MESSAGE", MB_OK); #endif OPT_DEMO_OUTPUT } // DLL entry point // Technically required, but don't do anything here. // Initializations belong into the OnLoad() function, // where they get executed at run-time. // Doing things here at load-time is a bad idea, // as some functionalitz might not be properly initialized // (including error/handling). BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: #ifdef OPT_DEMO_OUTPUT AllocConsole(); #endif OPT_DEMO_OUTPUT break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: #ifdef OPT_DEMO_OUTPUT FreeConsole(); #endif OPT_DEMO_OUTPUT break; } return TRUE; }  
      Source.zip
      DllAccess.au3