Jump to content

Autoit modification date


Recommended Posts

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
Link to comment
Share on other sites

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.

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Not sure what you mean by dynamic?

Why are you checking every 5 seconds?

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

Link to comment
Share on other sites

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

Edited by TheSaint

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

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

Link to comment
Share on other sites

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,
 

Link to comment
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
 Share

×
×
  • Create New...