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

    • nooneclose
      By nooneclose
      How to use _Excel_RangeSort to sort my excel file by three different headers Column A1, B1, and C1 have headers on which I want to sort by. The headers on which I want to sort are department, employee type, and name.
      I still really new to AutoIt so I do not actually know how to properly start this line or lines of code, to be honest. The example code is the best I can do.
      _Excel_RangeSort($OpenWorkbook, Default, "A1:C1", "1:1", $xlDescending, Default, $xlYes, Default, $xlSortRows) I just need to sort by those three headers in that order of department, employee type, and name, plus in descending order.
       
      any and all help would be greatly appreciated.  Thank you!
    • Eminence
      By Eminence
      Hello,
      Using SQLite, I was trying to select a specific column with having duplicate entries removed by using the DISTINCT function. 
      Local $sQuery = "SELECT DISTINCT supervisor, COUNT(DISTINCT employee_name) FROM data_db What the above snippet does is just list only one supervisor but with the total count of unique employee names in the whole database when it should be listing out all supervisor entries from the database and list the total count of employees per each supervisors. If I remove the COUNT function, it does list out all unique entries of supervisor names from the list. Attached is a screenshot of an example database as well. 
      Any help will be much appreciated. Thank you!

    • PramodR
      By PramodR
       
      I see couple of ways to import module ,  one with specifying absolute path of the file to get imported, by this logic i believe to import a specific module will be like #include <c:\modulepath\duplicatemodule.au3>
      but i see some registry changes also made in this link , can someone explain why that registry change is really required.
       
    • fikri
      By fikri
      Hello to all.
      I would like to make automation for LabView compiled project exe.
      Actually I just need to get values (results) from labview textboxes. But since labview not using MS componenents, is that possible.
      I spend lot of time by googling and tried some scripts but without success.
      Is this possible at all? 
      Also, I cannot read text properties window by any spy tool?  
       
      here is what I have from AutoIt Info:
       
      Class: LVDChild
      Position: -8, -8
      Size: 1456, 876
      Style: 0x17CF0000
      ExStyle: 0x00040300
      Handle: 0x001F041C >>>> Control <<<<
      Class: 
      Instance: 
      ClassnameNN: 
      Name: 
      Advanced (Class): 
      ID: 
      Text: 
      Position: 
      Size: 
      ControlClick Coords: 
      Style: 
      ExStyle: 
      Handle:  >>>> Mouse <<<<
      Position: 1256, 267
      Cursor ID: 0
      Color: 0xFAFAFA >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<<
      >>>> Hidden Text <<<<
    • toto22
      By toto22
      I have a string that look like this:

      WIFI    13.8    26.59
      BCRX    9.6    13.34
      GTES    8.5    11.15
      DFRG    5.9    33.02
      GIL    5.5    12.08
      How can I simply build an Array with it?
       
×