NiceBoy1234

Autoit modification date

9 posts in this topic

#1 ·  Posted (edited)

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



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

#3 ·  Posted (edited)

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

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

#5 ·  Posted (edited)

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

#6 ·  Posted (edited)

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

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

#8 ·  Posted (edited)

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

#9 ·  Posted (edited)

.

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

    • rudi
      By rudi
      Hello.
      I'm too stupid to see my mistake:
      To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.
      Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting
      The "TIFF Header Format" is easy:
      Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)
      --> II
      Offset 02h, 2 Byte = Version Nr.
      Offset 04h, 4 Byte = pointer to first IFD entry
      Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3
       

      Howto read and analyse the binary content correctly? This is my messy, not operational code:
       
      $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
      111111.TIF
    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • Viki
      By Viki
      This is my first time here so please dont bombard me that what a silly question I am asking!!
      I have 500 rows (A1:A500) in a spreadsheet and I just want to copy one by one row and then paste into another application and then press enter, loop should repeat this until finishes all 500 rows.
      I have looked at clipget(), clip(put() but dont know how to select next row in next turn. I also looked at Array to store but again no luck. Can some guide me please..