Jump to content
Sign in to follow this  
TylerH

My code that checks for a change in the number of files isn't working

Recommended Posts

TylerH

I have the following code that successfully reads the amount of files in a folder:

$hNumberofFiles = 0
Func _UBound($hNumberofFiles)
    Global $n
    Global $hPath = "T:\"
    $hNumberofFiles = _FileListToArray($hPath, "*.tif", 1)
    For $n=UBound($hNumberofFiles) - 1 to 0 Step -1
        If StringLen($hNumberofFiles[$n]) > 0 Then ExitLoop
        Next
    Return $n
EndFunc
$hFileCount = _UBound($hNumberofFiles)

(I tested it via a MsgBox returning _UBound($hNumberofFiles), which returned the correct number)

However, I can't seem to write a working loop to check for an increase in the number of files:

$hFileCountNew = $hFileCount
MouseClick("", 280, 420, 1, 10) ;Clicks a button to print files to a virtual printer AKA it writes files to a folder
Sleep(700)
While $hFileCountNew <= _UBound($hNumberofFiles) ;If the number of files is still the same, then the report is still loading, so just wait and check again in three seconds
    Sleep(3000)
WEnd

Specifically, the while loop doesn't seem to be working, so the script just sleeps forever/goes idle.

Edited by TylerH

Share this post


Link to post
Share on other sites
TylerH

Sorry all, I've solved my own problem by replacing the While Loop with a Do ... Until loop:

Do ;If the number of files is still the same, then the report is still loading, so just wait and check again in three seconds
    Sleep(3000)
Until _UBound($hNumberofFiles) > $hFileCount

 

Share this post


Link to post
Share on other sites
JLogan3o13

@TylerH another option, fewer lines:

#include <File.au3>
#include <MsgBoxConstants.au3>

While 1
    MsgBox($MB_OK, "", _findFileNum())
    Sleep(1000)
WEnd


Func _findFileNum()
    Local $sPath = @DesktopDir & "\Test"
    Local $aFiles = _FileListToArray($sPath, "*.tiff", $FLTA_FILES)
    Return UBound($aFiles) - 1
EndFunc

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
TylerH
1 minute ago, JLogan3o13 said:

@TylerH another option, fewer lines:

#include <File.au3>
#include <MsgBoxConstants.au3>

While 1
    MsgBox($MB_OK, "", _findFileNum())
    Sleep(1000)
WEnd


Func _findFileNum()
    Local $sPath = @DesktopDir & "\Test"
    Local $aFiles = _FileListToArray($sPath, "*.tiff", $FLTA_FILES)
    Return UBound($aFiles) - 1
EndFunc

 

Wouldn't the While loop have to be after the Func? Otherwise it would be calling an undefined function, no?

Share this post


Link to post
Share on other sites
JLogan3o13

@TylerH, no AutoIt does not require your funcs to be above the calling point. In fact, as you look through examples in the help file and on the forum you will see most often they are put at the bottom, with your main body of code calling them.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
RyukShini
1 hour ago, JLogan3o13 said:

@TylerH, no AutoIt does not require your funcs to be above the calling point. In fact, as you look through examples in the help file and on the forum you will see most often they are put at the bottom, with your main body of code calling them.

I can vouch for this!
I wrote something once and all my functions were in the bottom of my script.

Share this post


Link to post
Share on other sites
TylerH
1 hour ago, JLogan3o13 said:

@TylerH another option, fewer lines:

#include <File.au3>
#include <MsgBoxConstants.au3>

While 1
    MsgBox($MB_OK, "", _findFileNum())
    Sleep(1000)
WEnd


Func _findFileNum()
    Local $sPath = @DesktopDir & "\Test"
    Local $aFiles = _FileListToArray($sPath, "*.tiff", $FLTA_FILES)
    Return UBound($aFiles) - 1
EndFunc

 

By the way, I don't need to create a MsgBox; I just need to store the number of files as a variable so that the rest of my code waits until the number of files != the variable stored at the beginning of the snippet.

Share this post


Link to post
Share on other sites
JLogan3o13

It was just an example, you can put the value into a var at the beginning, and then constantly check against it in the While loop

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

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
Sign in to follow this  

  • Similar Content

    • ternal
      By ternal
      Hi,
      Recently I have had the need to do a sort and then do a second sort while the item of the first sort stays the same ( double sorting , first on column x then while column x is the same sort column y).
      I did not put much efffort into error checking but so far I did not need it.
      For my applications so far it works perfectly however if someone is willing I want to test this extensivly.
      If anyone has big lists of random stuff to sort could you try this out please?
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArraySort_Double ; Description ...: ; Syntax ........: _ArraySort_Double (Byref $array[, $first_index = Default[, $second_index = Default[, $ascending = Default]]]) ; Parameters ....: $array - 2d array to sort. ; $first_index - [optional] first column to sort. Default is 0. ; $second_index - [optional] second column to sort. Default is 1. ; $ascending - [optional] ascending/descending. Default is 1. ; Return values .: 1 if no errors occured , -1 if errors occured ; Author ........: Ternal ; Remarks .......: Needs excessive testing. ; Related .......: _arraysort() ; =============================================================================================================================== Func _ArraySort_Double (byref $array, $first_index = Default, $second_index = Default, $ascending = Default) Local $temp_value Local $counter = 1 If UBound($array, $UBOUND_DIMENSIONS) <> 2 Then MsgBox(0, "error", "error") return -1 EndIf If $first_index = Default Then $first_index = 0 If $second_index = Default Then $second_index = 1 If $ascending = Default Then $ascending = 1 _ArraySort($array, $ascending, 0, 0, $first_index); you can alter settings of primary sort here If @error Then MsgBox(0, "error", @error) return -1 EndIf $temp_value = $array[0][$first_index] For $x = 1 to UBound($array, 1) - 1 If Mod( $x, 10000) = 0 Then ConsoleWrite("at " & $x & " of a total : " & UBound($array, 1) & @CRLF) If $array[$x][$first_index] = $temp_value Then $counter+= 1 If $x = UBound($array, 1) - 1 Then; do last line here(if last line is not a new item) _ArraySort($array, $ascending, $x - $counter, $x, $second_index);you can alter settings of secondary sort here(don't forget to place line 34 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf EndIf Else If $counter > 0 Then ;at least 2 of the same _ArraySort($array, $ascending, $x - $counter, $x - 1, $second_index);you can alter settings of secondary sort here(don't forget to place line 29 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf $counter = 1 EndIf EndIf $temp_value = $array[$x][$first_index] Next Return 1 EndFunc Kind regards, Ternal
    • TrashBoat
      By TrashBoat
      So I've made this script that detects how long i have held down my left mouse button for and stores the information in an array and then sorts its using _ArraySort but the output is half sorted half broken.
      Here's my script:
      HotKeySet("{F1}","_exit") #include <Misc.au3> #include <Timers.au3> #include <Array.au3> Local $dll = DllOpen("user32.dll") $on = False Global $array[0] While(1) If _IsPressed(01,$dll) Then $timer = _Timer_Init() While _IsPressed(01,$dll) Sleep(1) WEnd $time = _Timer_Diff($timer) _ArrayAdd($array,"Time: " & Floor($time) & " ms") ;~ ConsoleWrite("Time: " & Floor($time) & " ms" & @CRLF) EndIf Sleep(50) WEnd Func _exit() _ArraySort($array) _ArrayDisplay($array) Exit EndFunc And the output:

      See how its not sorted?  What is the problem here?
    • MrCheese
      By MrCheese
      Hi guys,
      See attached for an array example.
      to simplify what i want to achieve,  I want to split this array into 9 different csv files.
      the first file would contain the list of "key" and the corresponding "ID1", the second would have "key" and the "ID2", the third would have "key" and "ID3"
      However, I want to remove all the rows that don't have an ID recorded in the respective ID2, ID3 4...5...6 etc, so the file only contains row items with a key and the ID.
      Would be the best way to loop through the rows and delete the row if the array field is blank - would I then need to repeat that row ID to check that the row that its replaced is also empty (ie the one after the one I just deleted)? I see this getting messy.
      or _arraySort, and delete everything below the last filled row? <-- this might be best?
      Or should I use the excel UDF, apply a filter (not selecting the blanks), then create/export to the array->csv?
       
      Super keen to hear your thoughts.
      thanks!
       
       
       
       
      IDArray.csv
    • milkmoron
      By milkmoron
      I am trying to search in a web browser dates XX/XX/XXXX that are also links. I want to click them after and remove them from the array. This is all I have so far. Nothing shows up. What am I doing wrong?
      ControlFocus ("Customer Center", "", "")
      Local $aArray = StringRegExp('(..)/(..)/(....)', '(..)/(..)/(....)', $STR_REGEXPARRAYFULLMATCH)
      For $i = 0 To UBound($aArray) - 1
          MsgBox($MB_SYSTEMMODAL, "RegExp Test with Option 2 - " & $i, $aArray[$i])
      Next
       
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
×