Jump to content
NiceBoy1234

Autoit modification date

Recommended Posts

NiceBoy1234

I am trying to dynamically get folders and their modification date, I was orientated by this:

; Initial Launch, grab current GetTime
$file1_1 = FileGetTime("X:\aescripts\testimg", 0, 1)

Timecheck()

Func Timecheck()

      $file1_2 = FileGetTime("X:\test\testimg", 0, 1)

      If $file1_1 == $file1_2 Then
         ConsoleWrite("Folder 1 not modified" & @CRLF);
      ElseIf $file1_1 <> $file1_2 Then
         ConsoleWrite("Folder 1 modified" & @CRLF)
      EndIf

; Initial Launch, grab current GetTime
$file1_1 = FileGetTime("X:\test\testimg", 0, 1)

EndFunc

; Initial Launch, grab current GetTime
$file1_1 = FileGetTime("X:\test\testimg", 0, 1)

While 1
    Sleep(5000)
    Timecheck()
WEnd


That works, but it is not dynamic.

So I did code following but it does not work properly.

 

   Local $sFootage_01 = "Z:\Footage\ClothImgs\"    

      Local $aFileListFootageFolder_01 = _FileListToArray($sFootage_01, "*")

      ; Initial Launch, grab current GetTime
      For $i = 0 To UBound($aFileListFootageFolder_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolder_01[$i]
         $getTimeNewFootageFolderInit_01 = FileGetTime($newFootageFolder_01, 0, 1)
         ConsoleWrite("First Filename " & $newFootageFolder_01 & @CRLF)
      Next

   Func Timecheck()

      Local $aFileListFootageFolderRe_01 = _FileListToArray($sFootage_01, "*")

      If @error = 1 Then
         ConsoleWrite("not valid path" & @CRLF)
         Exit
      EndIf
      If @error = 4 Then
         ConsoleWrite("could not find any data" & @CRLF)
         Exit
      EndIf

      For $i = 0 To UBound($aFileListFootageFolderRe_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolderRe_01[$i]
         ConsoleWrite("ArrH " & $aFileListFootageFolderRe_01[$i] & @CRLF)
         $getTimeNewFootageFolder_01 = FileGetTime($newFootageFolder_01, 0, 1)
         ConsoleWrite("ZZZ First Filename " & $newFootageFolder_01 & @CRLF)

         Local $aGetTimeNewFootageFolder_01 = _FileListToArray($newFootageFolder_01, "*")
         For $u = 0 To UBound($aGetTimeNewFootageFolder_01) -1
             If $getTimeNewFootageFolderInit_01 == $getTimeNewFootageFolder_01 Then
                ConsoleWrite($newFootageFolder_01 & " has not been changed" & @CRLF)
             ElseIf($getTimeNewFootageFolderInit_01 <> $getTimeNewFootageFolder_01 And $aGetTimeNewFootageFolder_01[0] == 11) Then
                ConsoleWrite("File 1 has been changed and has " & $aGetTimeNewFootageFolder_01[0] & " images" & @CRLF)
                ConsoleWrite("Time 1.1: " & $getTimeNewFootageFolderInit_01 & @CRLF & "1.2: " & $getTimeNewFootageFolder_01 & @CRLF)
                WinKill($hWnd, "")
                Sleep(8000)
                RunCm()
                ListFolders()
                ExitLoop
             ElseIf($getTimeNewFootageFolderInit_01 <> $getTimeNewFootageFolder_01 And $aGetTimeNewFootageFolder_01[0] <> 11) Then
                ConsoleWrite("Path " & $newFootageFolder_01 & " modification date has changed, number of images: " & $aGetTimeNewFootageFolder_01[0] & " files/folders" & @CRLF)
             Else
                ConsoleWrite("Else Statement" & @CRLF)
             EndIf
         Next
      Next


      $aFileListFootageFolderInit_01 = _FileListToArray($sFootage_01, "*")

      ; Initial Launch, grab current GetTime
      For $i = 0 To UBound($aFileListFootageFolder_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolder_01[$i]
         $getTimeNewFootageFolderInit_01 = FileGetTime($newFootageFolder_01, 0, 1)
      Next
   EndFunc

      $aFileListFootageFolderInit_01 = _FileListToArray($sFootage_01, "*")

      ; Initial Launch, grab current GetTime
      For $i = 0 To UBound($aFileListFootageFolder_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolder_01[$i]
         $getTimeNewFootageFolderInit_01 = FileGetTime($newFootageFolder_01, 0, 1)
      Next

   ; check every 5s if files in footage folder has been changed
   While 1
      Sleep(5000)
      ConsoleWrite("While Loop " & @CRLF)
      Timecheck()
   WEnd

It always goes to the first ElseIf Statement and tells me that the files have been changed.
So I printed out the modification dates and this varaible shows correctly the current modification date of the subfolder $getTimeNewFootageFolder_01 and this
$getTimeNewFootageFolder_01 does show another modification date of another folder which I do not understand.

Again the code (not dynmaic one) above works, but trying to make it dynmacly did not work.
 

Edited by NiceBoy1234

Share this post


Link to post
Share on other sites
TheSaint

Not exactly sure what you are wanting to do?
Are you just wanting the dates of all files in a folder?
To do a comparison with the same files in another folder?

And to be honest, I prefer things simple, so big long names and busy looking code does my head in.
I keep things simple, that I can understand at a glance, even if that means using extra steps and lines.
Similar names also don't help, as it takes me away, checking what they are all the time.
None of that is intuitive to holding an overall picture/map/structure in one's head.

But each to their own.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
NiceBoy1234

I Basically want to check if the modification date of a folder has changed.
I tried to make the code above dynamically, if you would copy the first part of the code and change the path you may would understand it better.

Edited by NiceBoy1234

Share this post


Link to post
Share on other sites
TheSaint

Not sure what you mean by dynamic?

Why are you checking every 5 seconds?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
TheSaint

Are you wanting to continually monitor the same folder indefinitely for changes?

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
NiceBoy1234

I check every 5 seconds, because if the user creates another folder, that folder gets checked to.
I check for folders in the following path :

Z:\Footage\ClothImgs\

If there are folder I check for their file size ( in this case they got images ) and the modification date.
So if I delete a file or something similiar the modification date of that folder changes and I will do something ...

So Yeah one could say that I want to check indefinitely the folder/s for changes.

Edited by NiceBoy1234

Share this post


Link to post
Share on other sites
TheSaint

By my reckoning, you keep assigning to the same variable ($getTimeNewFootageFolderInit_01) for every sub-folder. And perhaps you also need to use a backslash between source folder and sub-folder? (i.e. $sFootage_01 & "\" & $aFileListFootageFolder_01[$i])

; Initial Launch, grab current GetTime
      For $i = 0 To UBound($aFileListFootageFolder_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolder_01[$i]
         $getTimeNewFootageFolderInit_01 = FileGetTime($newFootageFolder_01, 0, 1)
         ConsoleWrite("First Filename " & $newFootageFolder_01 & @CRLF)
      Next

Those two things strike me as issues that need dealing with.

But I don't know, I'm getting awfully muddled by your naming convention, which makes it hard to troubleshoot. It seems to me you might be getting things mixed up, but I'm not really sure.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
VIP

Results of three hours working with less brainy brain:

File Monitor!

#include <File.au3>
#include <WinAPI.au3>
#include <WinAPIFiles.au3>

Opt('TrayAutoPause', 0)

Global Const $sPathtoCheck = @ScriptDir ; "Z:\Footage\ClothImgs\"

If Not FileExists($sPathtoCheck) Then
    DirCreate($sPathtoCheck)
    If Not FileExists($sPathtoCheck) Then
        MsgBox(48, 'Error', 'Unable to create folder.')
        Exit
    EndIf
EndIf

FileChangeDir($sPathtoCheck)
OnAutoItExitRegister('_OnExit')

Global $g_ahObj[2]
$g_ahObj[0] = _WinAPI_FindFirstChangeNotification($sPathtoCheck, $FILE_NOTIFY_CHANGE_FILE_NAME)
$g_ahObj[1] = _WinAPI_FindFirstChangeNotification($sPathtoCheck, $FILE_NOTIFY_CHANGE_LAST_WRITE)

If (Not $g_ahObj[0]) Or (Not $g_ahObj[1]) Then
    MsgBox(48, 'Error', 'Unable to create change notification.')
    Exit
EndIf

Local $tObjs = DllStructCreate('ptr;ptr')
Local $paObj = DllStructGetPtr($tObjs)
DllStructSetData($tObjs, 1, $g_ahObj[0])
DllStructSetData($tObjs, 2, $g_ahObj[1])

Global $aListFileChecked, $aListTimeFileChecked, $sOldFileTime
Global $aListFileToCheck, $aListTimeFileToCheck, $sCurFileTime
Global Const $aArray[1] = [0]

$aListFileChecked = _FileListToArray($sPathtoCheck, "*", $FLTA_FILES)
If Not IsArray($aListFileChecked) Then $aListFileChecked = $aArray
For $i = 1 To $aListFileChecked[0] - 1
    $aListFileChecked[$i] = $aListFileChecked[$i] & "|" & FileGetTime($aListFileChecked[$i], $FT_MODIFIED, $FT_STRING)
    ConsoleWrite("+ File: " & _RetunFileOrTime($aListFileChecked[$i], 0) & "  - Time: " & _RetunFileOrTime($aListFileChecked[$i], 1) & @CRLF)
Next

TraySetToolTip("Right click to me and Click Exit to Exit")
TrayTip("File Monitor", "Right click to TrayIcon and Click Exit to Exit", 3)

Local $iID
While 1
    Sleep(1)
    $iID = _WinAPI_WaitForMultipleObjects(2, $paObj, 0, 0)
    If $iID = 0 Or $iID = 1 Then
        _CheckFileTime()
        If Not _WinAPI_FindNextChangeNotification($g_ahObj[$iID]) Then
            MsgBox(48, 'Error', 'Unexpected error.')
            _OnExit()
        EndIf
    Else
        ContinueLoop
    EndIf
WEnd

Func _RetunFileOrTime($FileAndTime, $Type = 0); 1 Time
    ;ConsoleWrite("> " &$FileAndTime&" - "&$Type& @CRLF)
    If Not StringInStr($FileAndTime, "|") Then Return $FileAndTime
    If $Type <> 1 Then Return StringLeft($FileAndTime, StringInStr($FileAndTime, "|") - 1)
    Return StringTrimLeft($FileAndTime, StringInStr($FileAndTime, "|"));TIME
EndFunc   ;==>_RetunFileOrTime

Func _CheckFileTime()
    ConsoleWrite("- Some file is changed: Modified/Created/Deleted " & @CRLF)
    $aListFileToCheck = _FileListToArray($sPathtoCheck, "*", $FLTA_FILES, False)
    If Not IsArray($aListFileToCheck) Then $aListFileToCheck = $aArray
    For $i = 1 To $aListFileToCheck[0] - 1
        $aListFileToCheck[$i] = $aListFileToCheck[$i] & "|" & FileGetTime($aListFileToCheck[$i], $FT_MODIFIED, $FT_STRING)
        ;ConsoleWrite("! File: " &_RetunFileOrTime($aListFileToCheck[$i],0)&"  - Time: "& _RetunFileOrTime($aListFileToCheck[$i],1)& @CRLF)
        For $x = 1 To $aListFileChecked[0] - 1
            If _RetunFileOrTime($aListFileToCheck[$i], 0) = _RetunFileOrTime($aListFileChecked[$x], 0) Then
                If _RetunFileOrTime($aListFileToCheck[$i], 1) <> _RetunFileOrTime($aListFileChecked[$x], 1) Then
                    ConsoleWrite("! File is changed: " & _RetunFileOrTime($aListFileToCheck[$i], 0) & @CRLF)
                    ExitLoop
                EndIf
            EndIf
        Next
    Next
    $aListFileChecked = $aListFileToCheck
EndFunc   ;==>_CheckFileTime

Func _OnExit()
    For $i = 0 To 1
        If $g_ahObj[$i] Then
            _WinAPI_FindCloseChangeNotification($g_ahObj[$i])
        EndIf
    Next
    ;DirRemove($sPathtoCheck, 1)
EndFunc   ;==>_OnExit

 

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites
NiceBoy1234

.

Edited by NiceBoy1234

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

    • santoshM
      By santoshM
      How can i exit from a procedure in auto
      Func test() if x=o then     return endif endFunc  
    • Valnurat
      By Valnurat
      Hi
      Small question.
      I trying to find all index in an array with value higher than 7.
      How can that be possible?
    • corz
      By corz
      Associative Array Functions
      I've seen a couple of UDFs for this on the forum. One of them I quite like. But it's still nearly not as good as this method, IMHO.
      I don't recall if I discovered the "Scripting.Dictionary" COM object myself or if I got the original base code from somewhere online. I have recently searched the web (and here) hard for any AutoIt references to this, other than my own over the years I've been using this (in ffe, etc..), and I can find nothing, so I dunno. If anyone does, I'd love to give credit where it's due; this is some cute stuff! It could actually be all my own work! lol
      At any rate, it's too useful to not have posted somewhere at autoitscript.com, so I've put together a wee demo.
      For those who haven't heard of the COM "Scripting.Dictionary".. 
      If you've ever coded in Perl or PHP (and many other languages), you know how useful associative arrays are. Basically, rather than having to iterate through an array to discover it's values, with an associative array you simply pluck values out by their key "names".
      I've added a few functions over the years, tweaked and tuned, and this now represent pretty much everything you need to easily work with associative arrays in AutoIt. En-joy!
      The main selling point of this approach is its simplicity and weight. I mean, look at how much code it takes to work with associative arrays! The demo is bigger than all the functions put together! The other selling point is that we are using Windows' built-in COM object functions which are at least theoretically, fast and robust.
      I've used it many times without issues, anyhow, here goes..
      ; Associative arrays in AutoIt? Hells yeah! ; Initialize your array ... global $oMyError = ObjEvent("AutoIt.Error", "AAError") ; Initialize a COM error handler ; first example, simple. global $simple AAInit($simple) AAAdd($simple, "John", "Baptist") AAAdd($simple, "Mary", "Lady Of The Night") AAAdd($simple, "Trump", "Silly Man-Child") AAList($simple) debug("It is said that Trump is a " & AAGetItem($simple, "Trump") & ".", @ScriptLineNumber);debug debug("") ; slightly more interesting.. $ini_path = "AA_Test.ini" ; Put this prefs section in your ini file.. ; [test] ; foo=foo value ; foo2=foo2 value ; bar=bar value ; bar2=bar2 value global $associative_array AAInit($associative_array) ; We are going to convert this 2D array into a cute associative array where we ; can access the values by simply using their respective key names.. $test_array = IniReadSection($ini_path, "test") for $z = 1 to 2 ; do it twice, to show that the items are *really* there! for $i = 1 to $test_array[0][0] $key_name = $test_array[$i][0] debug("Adding '" & $key_name & "'..");debug ; key already exists in "$associative_array", use the pre-determined value.. if AAExists($associative_array, $key_name) then $this_value = AAGetItem($associative_array, $key_name) debug("key_name ALREADY EXISTS! : =>" & $key_name & "<=" , @ScriptLineNumber);debug else $this_value = $test_array[$i][1] ; store left=right value pair in AA if $this_value then AAAdd($associative_array, $key_name, $this_value) endif endif next next debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) debug(@CRLF & "Removing 'foo'..");debug AARemove($associative_array, "foo") debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) debug(@CRLF & "Removing 'bar'..");debug AARemove($associative_array, "bar") debug(@CRLF & "Array Count: =>" & AACount($associative_array) & "<=" , @ScriptLineNumber);debug AAList($associative_array) quit() func quit() AAWipe($associative_array) AAWipe($simple) endfunc ;; Begin AA Functions func AAInit(ByRef $dict_obj) $dict_obj = ObjCreate("Scripting.Dictionary") endfunc ; Adds a key and item pair to a Dictionary object.. func AAAdd(ByRef $dict_obj, $key, $val) $dict_obj.Add($key, $val) If @error Then return SetError(1, 1, -1) endfunc ; Removes a key and item pair from a Dictionary object.. func AARemove(ByRef $dict_obj, $key) $dict_obj.Remove($key) If @error Then return SetError(1, 1, -1) endfunc ; Returns true if a specified key exists in the associative array, false if not.. func AAExists(ByRef $dict_obj, $key) return $dict_obj.Exists($key) endfunc ; Returns a value for a specified key name in the associative array.. func AAGetItem(ByRef $dict_obj, $key) return $dict_obj.Item($key) endfunc ; Returns the total number of keys in the array.. func AACount(ByRef $dict_obj) return $dict_obj.Count endfunc ; List all the "Key" > "Item" pairs in the array.. func AAList(ByRef $dict_obj) debug("AAList: =>", @ScriptLineNumber);debug local $k = $dict_obj.Keys ; Get the keys ; local $a = $dict_obj.Items ; Get the items for $i = 0 to AACount($dict_obj) -1 ; Iterate the array debug($k[$i] & " ==> " & AAGetItem($dict_obj, $k[$i])) next endfunc ; Wipe the array, obviously. func AAWipe(ByRef $dict_obj) $dict_obj.RemoveAll() endfunc ; Oh oh! func AAError() Local $err = $oMyError.number If $err = 0 Then $err = -1 SetError($err) ; to check for after this function returns endfunc ;; End AA Functions. ; debug() (trimmed-down version) ; ; provides quick debug report in your console.. func debug($d_string, $ln=false) local $pre ; For Jump-to-Line in Notepad++ if $ln then $pre = "(" & $ln & ") " & @Tab ConsoleWrite($pre & $d_string & @CRLF) endfunc  
      ;o) Cor
    • TrashBoat
      By TrashBoat
      Could someone help me create or give an idea of how to do a incrementing for loop that would do this: https://i.imgur.com/YFUt47H.gifv
      I'm having a hard time figuring it out :S
    • msd1994
      By msd1994
      I have a script that just adds some keyboard shortcuts for things like displaying the current song and artist, moving the window to the side so it won't pop up in my way, and play/pause, next song, previous song (these are the only 3 to still work since they don't need the window handle.)
      In some update recently, Spotify's window class swapped from "[CLASS:SpotifyMainWindow]" to "[CLASS:Chrome_WidgetWin_0]". Using the new class in my controls doesn't seem to work, I've tried getting the window handle from the process handle (_GetHwndFromPID($PID)) but that seems to fail as well.
      Does anybody have some idea of a way I could get this script working again?
       
      edit: seems like discord has the same window class name, so could be some issue with this? Still not sure of a way to solve the issue though, I added a function to get the handle of the active window and can just use that now, but it was able to find it on its own before on spotify startup or script startup which would be preferred.
       
      Thanks!
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.