Sign in to follow this  
Followers 0
rogerd2u

Check date info on two files and copy if different

12 posts in this topic

#1 ·  Posted (edited)

I've been using AutoIT for some time now, but have never worked much with the "Func" option. Thus, my reason for posting this request for help.

I've got a script that I'm trying to create that will compare two files (one on a server, one locally). If the server has a newer (or different) file date, I want to copy it to the local PC. I need to check approx. 6 different files using this approach.

I decided the best way to code it would be using Func, but can't get it work. Here's what I have:

;Local Date check function

    Func _GetLocalFileInfo ()
        If Not @error Then
        $timeinfo =  FileGetTime(@ProgramFilesDir & "\CSI\" & $filename, 1)
        $LocalCSItime = $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
        EndIf
        
    EndFunc  ;==>_GetLocalFileInfo

;Server Date check function

    Func _GetServerFileInfo ()
        If Not @error Then
        $timeinfo =  FileGetTime($CSIServerLocation & $filename, 1)
        $ServerCSItime = $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
        EndIf
    EndFunc  ;==>_GetServerFileInfo

The above functions are what I was planning on using for each of the files

Here's the part of my script that would call the functions:

$filename = @ProgramFilesDir & "\CSI\" & "fprint.ico"
    $date1 = _GetLocalFileInfo ($filename) ;See Func _GetLocalFileInfo
    $date2 = _GetServerFileInfo ($filename) ;See Func _GetServerFileInfo
    If $date1 <> $date2 Then
        FileCopy($CSIServerLocation & $filename, @ProgramFilesDir & "\CSI",1);If dates are different, do this
    EndIf

Each time I attempt to run the script, I get a "Error: Incorrect number of parameters in function call." message.

Can anyone help me correct the script (or possibly help me streamline it, to make it more efficient).

Thanks in advance for your help!!

Roger

Edited by rogerd2u

Roger O."When people show you who they are, believe them.” --Mark Twain

Share this post


Link to post
Share on other sites



$filename = @ProgramFilesDir & "\CSI\" & "fprint.ico"

$date1 = _GetLocalFileInfo($filename)

$filename = Inetget( use inetget function here to get the online version of the file... see help

$date2 = _GetServerFileInfo($filename)

If $date1 <> $date2 Then

FileCopy($CSIServerLocation & $filename, @ProgramFilesDir & "\CSI",1);If dates are different, do this

EndIf

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

$date1 = _GetLocalFileInfo ($filename) << your calling the function with $filename .. and here is the function: Func _GetLocalFileInfo() with NO Parameter....


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Sorry, but I'm not following either reply.

Valuater - The file on the server is on an in-house server, so the "inetget" command doesn't seem to fit at all.

SmOke_N - When I add the variable $filename to the Func, I get a "Error: Subscript used with non-Array variable."

Here's what I changed on the functions:

Func _GetLocalFileInfo ($filename)
        If Not @error Then
        $timeinfo =  FileGetTime(@ProgramFilesDir & "\CSI\" & $filename, 1)
        $LocalCSItime = $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
        EndIf
        
    EndFunc  ;==>_GetLocalFileInfo

;Server Date check function

    Func _GetServerFileInfo ($filename)
        If Not @error Then
        $timeinfo =  FileGetTime($CSIServerLocation & $filename, 1)
        $ServerCSItime = $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
        EndIf
    EndFunc  ;==>_GetServerFileInfo

Your help is greatly appreciated!!

Roger


Roger O."When people show you who they are, believe them.” --Mark Twain

Share this post


Link to post
Share on other sites

Here try this:

$CSIServerLocation = '';????
$directory = @ProgramFilesDir & "\CSI\"
$filename = "fprint.ico"
$date1 = _GetLocalFileInfo($directory, $filename);See Func _GetLocalFileInfo
$date2 = _GetServerFileInfo($CSIServerLocation, $filename);See Func _GetServerFileInfo
If $date1 <> $date2 Then
    FileCopy($CSIServerLocation & $filename, @ProgramFilesDir & "\CSI\" , 1);If dates are different, do this (You were missing a '\' here I believe.
EndIf

Func _GetLocalFileInfo ($d_Directory, $fz_filename)
    $timeinfo =  FileGetTime($d_Directory & $fz_filename, 1); your fileget time was looking like: FileGetTime(@ProgramFilesDir & '\CSI\' & @ProgramFilesDir & '\CSI\fprint.ico') << that's wrong
    If Not @error Then Return $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
EndFunc ;==>_GetLocalFileInfo

;Server Date check function

Func _GetServerFileInfo ($c_CSIServerLocation, $fz_filename)
    Local $ServerCSItime = ''
    $timeinfo =  FileGetTime($c_CSIServerLocation & $fz_filename, 1)
    If Not @error Then Return $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
EndFunc ;==>_GetServerFileInfo


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

$filename = @ProgramFilesDir & "\Autoit3\Au3info.exe"
$date1 = _GetFileInfo($filename)

$filename = @ProgramFilesDir & "\Autoit3\Autoit3.exe"
$date2 = _GetFileInfo($filename)

If $date1 <> $date2 Then
;FileCopy($CSIServerLocation & $filename, @ProgramFilesDir & "\CSI",1);If dates are different, do this
    MsgBox(0, "Test", "Files are different   ")
EndIf


Func _GetFileInfo($filename)
    If Not @error Then
        $timeinfo = FileGetTime( $filename, 1)
        $filename = $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
        Return $filename
    EndIf
    
EndFunc  ;==>_GetFileInfo 


#cs NOT NEEDED ITS THE SAME AS ABOVE
;Server Date check function
    
    Func _GetServerFileInfo ($filename)
    If Not @error Then
    $timeinfo =  FileGetTime($CSIServerLocation & $filename, 1)
    $ServerCSItime = $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
    EndIf
    EndFunc ;==>_GetServerFileInfo
#CE

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

HI,

thank you guys. I changed it to my needs.

_getLatestVersion('c:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\', 'c:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Save\', _
        "Replays2.au3", 0)

Func _getLatestVersion($ServerLocation, $LocalLocation, $filename, $option = 0)
    $LocalDate = _getLocalFileInfo($LocalLocation, $filename, 0)
    $ServerDate = _getServerFileInfo($ServerLocation, $filename, 0)
    If $LocalDate <> $ServerDate Then
        FileCopy($ServerLocation & $filename, $LocalLocation & $filename, 1)
    EndIf
EndFunc  ;==>_getLatestVersion

Func _getLocalFileInfo($LocalLocation, $filename, $option)
    $timeinfo = FileGetTime($LocalLocation & $filename, $option)
    If Not @error Then Return $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
EndFunc  ;==>_getLocalFileInfo

Func _getServerFileInfo($ServerLocation, $filename, $option)
    $timeinfo = FileGetTime($ServerLocation & $filename, $option)
    If Not @error Then Return $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
EndFunc  ;==>_getServerFileInfo

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Personally, I probably would have wrote mine like:

Local $CSIServerLocation = '';????
Local $directory = @ProgramFilesDir & "\CSI\"
Local $filename = "fprint.ico"
If _CompareFileTimes($directory, $CSIServerLocation, $filename) == 3 Then
    FileCopy($CSIServerLocation & $filename, @ProgramFilesDir & "\CSI\" , 1);If dates are different, do this (You were missing a '\' here I believe.
Else
    If @error = 0 Then MsgBox(0, 'Info', 'Error with Local File')
    If @error = 1 Then MsgBox(0, 'Info', 'Error with Sever File')
    If @error = 2 Then MsgBox(0, 'Info', 'Files were same date')
EndIf

Func _CompareFileTimes($Local_Directory, $Server_Directory, $fz_filename)
    Local $LocalGetTime =  FileGetTime($Local_Directory & $fz_filename, 1)
    If Not @error Then 
        $LocalTime = $LocalGetTime[1] & "/" & $LocalGetTime[2] & "/" & $LocalGetTime[0] & " " & $LocalGetTime[3] & " " & $LocalGetTime[4]
    Else
        SetError(0); allows you to error check to see what is failing if you want ie... If @error = 0 Then MsgBox(0, 'Info', 'Error with Local File')
        Return 0
    EndIf
    
    Local $ServerGetTime = FileGetTime($Server_Directory & $fz_filename, 1)
    If Not @error Then 
        $ServerTime = $ServerGetTime[1] & "/" & $ServerGetTime[2] & "/" & $ServerGetTime[0] & " " & $ServerGetTime[3] & " " & $ServerGetTime[4]
    Else
        SetError(1); allows you to error check to see what is failing if you want ie... If @error = 1 Then MsgBox(0, 'Info', 'Error with Sever File')
        Return 1
    EndIf
    
    If Not $LocalTime <> $ServerTime Then
        SetError(2); allows you to error check to see what is failing if you want ie... If @error = 2 Then MsgBox(0, 'Info', 'Files were same date')
        Return 2
    Else
        Return 3; Returning 3 means that they are in fact different
    EndIf
EndFunc
I have no way of testing this though :o

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

HI,

thank you guys. I changed it to my needs.

_getLatestVersion('c:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\', 'c:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Save\', _
        "Replays2.au3", 0)

Func _getLatestVersion($ServerLocation, $LocalLocation, $filename, $option = 0)
    $LocalDate = _getLocalFileInfo($LocalLocation, $filename, 0)
    $ServerDate = _getServerFileInfo($ServerLocation, $filename, 0)
    If $LocalDate <> $ServerDate Then
        FileCopy($ServerLocation & $filename, $LocalLocation & $filename, 1)
    EndIf
EndFunc ;==>_getLatestVersion

Func _getLocalFileInfo($LocalLocation, $filename, $option)
    $timeinfo = FileGetTime($LocalLocation & $filename, $option)
    If Not @error Then Return $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
EndFunc ;==>_getLocalFileInfo

Func _getServerFileInfo($ServerLocation, $filename, $option)
    $timeinfo = FileGetTime($ServerLocation & $filename, $option)
    If Not @error Then Return $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
EndFunc ;==>_getServerFileInfo

So long,

Mega

why have two functions that do the same thing???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

why have two functions that do the same thing???

8)

Edit: Nevermind... you weren't talking to me... Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

HEY, YOU GUYS ARE GREAT!!! Thanks SOOOO MUCH!

Roger


Roger O."When people show you who they are, believe them.” --Mark Twain

Share this post


Link to post
Share on other sites

why have two functions that do the same thing???

8)

Hmmh, :geek: , cause I had to answer that quickly. Changed it again. Thanks!

_getLatestVersion('N:\xf01145\', _
'c:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Save\', "Replays2.au3", 0)

Func _getLatestVersion($ServerLocation, $LocalLocation, $filename, $option = 0)
    $LocalDate = _getFileInfo($LocalLocation, $filename, 0)
    $ServerDate = _getFileInfo($ServerLocation, $filename, 0)
    If $LocalDate <> $ServerDate Then
        FileCopy($ServerLocation & $filename, $LocalLocation & $filename, 1)
    EndIf
EndFunc  ;==>_getLatestVersion

Func _getFileInfo($location, $filename, $option)
    $timeinfo = FileGetTime($location & $filename, $option)
    If Not @error Then Return $timeinfo[1] & "/" & $timeinfo[2] & "/" & $timeinfo[0] & " " & $timeinfo[3] & " " & $timeinfo[4]
EndFunc  ;==>_getLocalFileInfo

HEY, YOU GUYS ARE GREAT!!! Thanks SOOOO MUCH!

Roger

:o I agree!

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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
Sign in to follow this  
Followers 0