Jump to content

Recommended Posts

Posted (edited)

I'm trying to use _Date_Time_CompareFileTime to compare two filetimes before copying one, kind of like a folder sync (simple and primitive). One file is on an external flash and the other is in the @temp folder.

Here's the pertinent data from my script:

#include "MyFunctions.au3"
#include <Date.au3>
#include <Array.au3>

$savslist = StringTrimRight(@TempDir & "\" & @ScriptName, 4) & "\savs list.txt"

$listfile = FileOpen($savslist, 10)

ScanFolderSAVS("Decode-dial");generates a list of filenames on each line
ScanFolderSAVS("Homebrew");this one does the same

FileClose($listfile)

Dim $savfromlocations[3];some key words that will filter the location of the files in the list
$savfromlocations[0] = "\Action\"
$savfromlocations[1] = "\John Peta\"
$savfromlocations[2] = "\Konami\"

Dim $szDrive, $szDir, $szFName, $szExt;needed for pathsplit

For $n = 1 To _FileCountLines($savslist);starting loop through file list
    $currentsav = FileReadLine($savslist, $n);file being read
    $currentsavsplit = _PathSplit($currentsav, $szDrive, $szDir, $szFName, $szExt);file's path split into an array
    
    $savname = $currentsavsplit[3] & $currentsavsplit[4];just keep things tidy, filename extracted
    $savto = StringTrimRight(@TempDir & "\" & @ScriptName, 4);just to keep things tidy,folder where the scripts will be copied
    
    For $x = 0 To UBound($savfromlocations) - 1;loop to filter the file locations from the flash card
        If StringInStr($currentsav, $savfromlocations[$x]) <> 0 Then;this is the filter
            If FileExists($savto & $savfromlocations[$x] & $savname) = 1 Then;if file exists, compare dates to see which is newer
                $file1 = _WinAPI_CreateFile($currentsav,2)
                $file2 = _WinAPI_CreateFile($savto & $savfromlocations[$x] & $savname,2)
                
                $time1 = _Date_Time_GetFileTime($file1)
                $time2 = _Date_Time_GetFileTime($file2)
                
                If _Date_Time_CompareFileTime($time1[2], $time2[2]) = 1 Then
                    $savscopied[$savscopied[0] + 1] = $savfromlocations[$x] & $currentsavsplit[3]
                    $savscopied[0] += 1
                    FileCopy($currentsav, $savto & $savfromlocations[$x] & $savname, 8)
                EndIf
            Else;if file in $savto doesn't exist then copy it
                $savscopied[$savscopied[0] + 1] = $currentsavsplit[3]
                $savscopied[0] += 1
                FileCopy($currentsav, $savto & $savfromlocations[$x] & $savname, 8)
            EndIf
            ExitLoop
        EndIf
    Next
Next

For some reason, $time2 and $time1 are empty but the $file handles aren't. Could somebody help me on this? What am I doing wrong?

Edited by Zhelkus
Posted (edited)

I think you need to specify READ access level when opening the file:

$file1 = _WinAPI_CreateFile($currentsav,2,2)
$file2 = _WinAPI_CreateFile($savto & $savfromlocations[$x] & $savname,2,2)
Edited by zorphnog
Posted

I think you need to specify READ access level when opening the file:

$file1 = _WinAPI_CreateFile($currentsav,2,2)
$file2 = _WinAPI_CreateFile($savto & $savfromlocations[$x] & $savname,2,2)
Just tried it and nope, it wasn't it.

Could the problem be that one file being compared is stored on a FAT partition (flash card)? Would that have anything to do with WinAPI or date_time_getfiletime?

Thanks for trying tho.

Posted

Why don't you just use the builtin FileGetTime function for the comparison?

Oh dear... you just made me look SO stupid.... but I thank you for that :)

I completely overlooked it... don't have the slightest idea how... thank you.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...