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

    • Luigi
      By Luigi
      Greetings, someone can give a exemple, how send a error from a C#'s dll to AutoIt?
      I use this line, to send an error... but, I want get a error code In AutoIt with macro @error, it's possible?
       
      throw new ArgumentException("arquivo map não existe", "value" ); In this way, work, I know ther are error, but, @errror always is zero.
      I don't want this, I want a number as error code.
      Can you help me?
       
      Best regards
    • nss
      By nss
      Hi all,
       
      I am making a program in which I use Bass audio library (with the wrapper for autoit that I found here on forums I think) because of its support for dx effects.
      My problem, though, is that when effects as reverb or echo/delay are added, the channel length is not extended as to fit the tail of the effect, so if the file was really short, you wouldn't even hear the reverb at all.
      I've tried setting the  buffer parameter even to 60k ms, updating the channel length to 60k ms, but nothing makes it so that the effects aren't being cut off.
      I've heard that I could add silence manually to wave files by adding the chr(0) characters, but haven't had any luck doing that, either.
      What I'm doing:
      initialize bass use streamCreateFile to load the wave file with the fx flag and length parameter set to 60000 set the config buffer to 60000 use channel set fx to add dx8 reverb use channel play to play the sound use bass update to update the length to 60000  
      I even tried having only silence in one wave file and tried joining two wave files together, but that didn't work either.
       
      Any help would be very much appreciated.
    • Nareshm
      By Nareshm
      Hi All,
      I have excel file like this
      and i want to cut cell/text from excel to other software.

       
      I have to cut the cell of B column one by one and past into other software
      If Winexists("No Data Found")
      then restore cuted cell and goto next/down side cell
      How to do it ?
    • Mag91
      By Mag91
      Hey Community,
      cause im too new in the Auto it world i will try it with the your help. hopefully.
      I woud like to know how i can handle my Problem.
      ----
      I have a Excel Data with 362 random numbers.
      For Example:
      1166642335374 1172899897343
      .....
      this numbers are a part of the filepath ...example
      D:\Projekte\1166_64233_5374
      as u can see its the first number of the Excel data. After the first 4 numbers it shoud make a "_" than another 5 "_"
      This is my first question. How can i handle this to make it Shell execute.
       
      --------
      Second question:
      If i am in the path.
      For Example:
      D:\Projekte\1166_64233_5374
      the code shoud search for specific PDF Files.
      They are named like: 0050569E364B1ED79B900F73E62660EC.pdf
      the first 15 letters are always the same
      0050569E364B1ED
      when he found this data he has to copy it on a Folder on the Desktop.
      (There can also be 2 or 3 pdfs in one Folder with this letters)
      ----
      Please give me some help :-)
       
       
       
       
       
       
    • Mag91
      By Mag91
      Hey Everybody,
      as you know im on a very low autoit-level.
      My question is: How can i read all PDFs from a Folder wich is open and copy them to a Folder on a Desktop.
       
      The Folder wich contains the PDFs is variable Z:\Projektls\"*"*"*EVERYTIME ANOTHER ENDING"*"*"*"*"
      There can be 1 PDF or even 15 PDFs.
      i tried it with _FileListToArray and _FileCopy but i Need some help to understand this language
       
      THANKS!