Jump to content
coles

what is the best way to compare files

Recommended Posts

coles

What i am trying to do is compare date of destination and source, and if source file is newer than destination it copies the file to source.

Just posting a sample code of what i am trying to achieve

 

#include <Date.au3> ; Include Date constants
#include <File.au3>
#include <iNet.au3>
#include <_XMLDomWrapper.au3>


Global $xml1, $xml1monthday, $xml1year, $xml1format, $xml2, $xml2monthday, $xml2year, $xml2format, $xmldate

; Runs the XmlDate() function to determine the age of the Xml file
;=====================================================================
XmlDate()

Func XmlDate()
$Xml1 = RegRead("C:\Temp\m1.xml","XmlDate") ; pulls registry

$xml1monthday = StringTrimRight($xml1, 5) ; takes the month

$xml1year = StringTrimLeft($xml1, 6) ; takes the year out

$xml1format = ($xml1monthday & "/" & $xml1year) ; reorders the date

$Xml2 = RegRead("C:\Temp\m2.xml","XmlDate") ; pulls registry

$xml2monthday = StringTrimRight($xml2, 5) ; takes the month and

$xml2year = StringTrimLeft($xml2, 6) ; takes the year out

$xml2format = ($xml2monthday & "/" & $xml2year) ; reorders

if $Xml1 = "" And $Xml2 = "" Then
   FileCopy( "C:\temp\a1.txt", "C:\temp\anokh", 1);
Else
   FileDelete("c:\temp\a1/txt")
   EndIf
EndFunc

 

 

Any comments will be appreciated 

Thank you

Share this post


Link to post
Share on other sites
RickB75

Have you looked at these functions? They are in the help file.

FileGetTime ( "filename" [, option = 0 [, format = 0]] )
FileGetVersion ( "filename" [, "stringname"] )

Or... I just found this one that I've used before.

#include <Misc.au3>
_VersionCompare ( $sVersion1, $sVersion2 )

 

Edited by RickB75

Share this post


Link to post
Share on other sites
coles

@RickB75 Thank you

I think i will use Filegettime

if versioncompare has to be used,don't we have to add a version number in files?? i cannot edit existing files.

Share this post


Link to post
Share on other sites
RickB75

If you can use FileGetTime, you should be able to use 

StringCompare ( "string1", "string2" [, casesense = 0] )

to compare the two strings.

  • Like 2

Share this post


Link to post
Share on other sites
Autoyt443
Just now, RickB75 said:

If you can use FileGetTime, you should be able to use 

StringCompare ( "string1", "string2" [, casesense = 0] )

to compare the two strings.

 

Share this post


Link to post
Share on other sites
coles

Thanks @RickB75 @mikell for the replies.

@mikell with just 1 line of code you just showed how little i know about Autoit..

Many thanks as it works perfectly

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

    • gahhon
      By gahhon
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\..\Downloads\ALlogo.ico #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_HiDpi=y #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /rm /pe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** I found out that a lot of sources provided by AutoIT members like what I am recently using is the Metro UDF.
      On top of it, it always written the Region of code and red color. Then it also assign some value into some variable.
      May I know, what are their use and what is the purpose of doing?
      If I remove them, will affect the application?
      Thanks
    • gahhon
      By gahhon
      I don't find any relevant topic via Google Search. Please kindly advise how to read and update data in Google SpreadSheet.
      Thanks a lot.
    • gahhon
      By gahhon
      While Not _Login() _Initial_Check() WEnd Func _Login() Local $FLAG_LOGIN = _Password_Check() If @error = 1 Then _Close_Application() ElseIf @error = 2 Then _Metro_MsgBox(0, "", $FLAG_LOGIN) Return False Else ; $FLAG_LOGIN return TRUE _Metro_MsgBox(0, "", "Access granted!") Return True EndIf EndFunc  I do have a question regarding the While Not Loop.
      According to the code I post above, While Not _Login() is similar to While _Login() = False right?
      Which mean when _Login() return False and it will execute the _Initial_Check() function, but somehow the logic is not right and I also don't understand why While Not _Login() loop is executed as expected.
      What I wanna achieve is when _Login() is not success, which mean return False then it continue loop the _Login() function until it return True
      When It return True only execute the _Initial_Check() function.
      Please kindly clarify. Thanks
    • gahhon
      By gahhon
      I would like to copy the entire folder with current directory @WorkingDir
      paste into either Program Files or Program Files (x86)
      Global Const $CUR_WA_FOLDER = @WorkingDir & "\Test Folder" Global Const $DIR_FOLDER = _ProgramFilesDir() _Initial_Check() Func _Initial_Check() If FileExists($DIR_FOLDER & "\Test Folder") = 0 Then Local $Decisions = _Metro_MsgBox(4, "", "Do you want to install Test Application?") If $Decisions = "Yes" Then DirCopy($CUR_WA_FOLDER, $DIR_FOLDER, 1) Else _Close_Application() EndIf EndIf EndFunc Func _ProgramFilesDir() Local $ProgramFilesDir Switch @OSArch Case "X32" $ProgramFilesDir = "Program Files" Case "X64" $ProgramFilesDir = "Program Files (x86)" EndSwitch Return @HomeDrive & "\" & $ProgramFilesDir EndFunc  
    • nooneclose
      By nooneclose
      Is it possible to use Autoit to find every Monday within a date range? An example would be I want to find every Monday between 1/9/19 through 4/9/19. Then Autoit would give me all the dates on which Monday lands between those two dates. 
      Sorry but I don't have any code so far. I was wondering if it was even possible. I read the help file and I didn't see a function that could do that. 
×