Jump to content
dynamitemedia

need help with a FOR LOOP

Recommended Posts

dynamitemedia

i know this is simple but i cant seem to figure it out...

here is my code :
 

 
   For $s_idx = 1 To $search_things[0]
      If StringInStr(FileGetAttrib($search_root & $search_things[$s_idx]), 'D', 0, 1) Then
         $href = StringEncrypt(1, 'SandelPerieanu|' & StringLeft($search_root, StringInStr($search_root, '\', 0, -1) - 1) & '|' & $search_root & $search_things[$s_idx], $pass_encrypt)
         $s_dirs &= '<a class="padding1" href="folder-' & $href & '"><img align="middle" hspace="10" border=0 height="28px" width="28px" src="filefolder.png"><b>' & $search_things[$s_idx] & '</b></a><br>' & @CRLF
      Else
$files = $search_things[$s_idx]
Local $folder2check = $search_root
Local $vidType = "*.flv"
Local $FileList = _FileListToArray($folder2check , $vidType, $FLTA_FILES, True)


If @error Then
; display nothing
Else
For $i = 1 To $FileList[0]
  $okFiles = GetFileName($FileList[$i])
  ConsoleWrite("this is the files allowed : " & $okFiles  & @CRLF)
  $href = StringEncrypt(1, 'SandelPerieanu|' & $search_root & $okFiles, $pass_encrypt)
  $s_files &= '<a class="padding1" href="file-' & $href & '"><img align="middle" hspace="10" border=0 height="28px" width="28px" src="file.png"><b>' & $okFiles & '</b></a><br>' & @CRLF
Next
WEnd
EndIf
 EndIf
   Next

 Just trying to only show certain files NOT all file extension, no need to show  windows files etc...

 well it works BUT because of the for loop it is showing the files more than once,  i have been stuck on this for a few hours and not sure how else to get the correct files with out a for loop inside the other loop.  any ideas?

Obvisously only want to display the files once  this code starts about line 360 
 

   this code is from here:  

Share this post


Link to post
Share on other sites
javiwhite

Hey DynamiteMedia,

You could always add a stringInStr check to your code, prior to adding the data to the $s_Files var (I assume this is the one that's showing the files multiple times?)

Something like this

if StringInStr($s_files,$okfiles) = 0 then $s_files &= '<a class="padding1" href="file-' & $href & '"><img align="middle" hspace="10" border=0 height="28px" width="28px" src="file.png"><b>' & $okFiles & '</b></a><br>' & @CRLF

The above checks whether the filename is contained in the main string, and if it's not, Add it.

It's not the most sophisticated way of resolving the issue, But it's a quick fix that should help you achieve what you're trying to do.

Hope this helps

Javi


give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites
dynamitemedia

that worked great actually thanks!

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

    • omicron
      By omicron
      Hello!

      I am working on a function that I am just getting lost on. The goal is a multiple nested loop.

      Here are the steps:
      Contents of file1.txt::
      [topic] var1=Name var2=OtherName var3=SomeotheName Contents of file2.txt::
      [subTopic] top=sub1 top2=sub2 top3=sub3 The Shell I am working from::
      #include <file.au3> $file = "c:\yourfile.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) msgbox(0,'','the line ' & $i & ' is ' & $line) Next FileClose($file) Understanding however that the "msgbox" needs to then become a variable. in example the following::
      $file = "c:\yourfile.txt" FileOpen($file, 0) While true( prog.exe is running && "WinName" is open) do For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) ;Open File to log "current location of file 1" FileWriteLine ("filename", $i & ' is ' & $line) var = $line Next $file2 = "c:\yourfile.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) ; OpenFile to log "Current location of file 2" FileWriteLine ("filename", $i & ' is ' & $line) Next FileClose($file2) FileClose($file) The goal in written form is the following ::

      While in "OpenWindow"
          read from file 1 starting at line 1 until end of file.
         file 1 is a list of names to be searched.
         With $line selected, add this element to the element in file 2.
       
      The search of a variables in list 1 and list 2 differ on the amount of posts that day. (This is not a web based platform, it is a game) I need to search 2 names and take a screenshot of the out put. The sizes of the names list depend on the activity of names at the time of search.
      This loop continues until all the names from both lists have been searched. Mostly in the format of::
      File1= item
      File2= Vendor
       
      Item + Vendor  ( Capture screen, scroll) -- Not sure how to detect if I need to scroll)
       
      Thank you for your help and support!
    • Jackized
      By Jackized
      Is there a way to loop back to the beginning and keep the already entered data in the GUI Input boxes? I can GUIDelete and start a new GUI but all the typed data has to be redone. Here is a sample.

       
      #Include <GuiConstants.au3> Dim $msg,$okbutton,$cancelbutton,$objOU,$intAccValue,$strGroup1,$strGroup2 Dim $strFirstName,$strLastName,$strUserName,$strUserName2,$strPassword,$strDescription,$strContainer Dim $Combo,$Duration Do $Form1 = GuiCreate("", 300, 300)          GUISetBkColor(0xA6CAF0)         GuiCtrlCreateLabel("First Name:", 50, 10)         $strFirstName = GuiCtrlCreateInput("", 50, 25, 200, 20)         GUICtrlSetState ( $okbutton, $GUI_FOCUS )         GuiSetState()     $okbutton = GUICtrlCreateButton ("OK",75,240,50,20)     $cancelbutton = GUICtrlCreateButton ("Cancel",175,240,50,20) While 1     $msg = GUIGetMsg()     Select     Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton             Exit     Case $msg = $okbutton             $strFirstName = GUICtrlRead($strFirstName)             ExitLoop     EndSelect Wend $len = StringLen($strFirstName)     If $len > "20" then         MsgBox(0, "ERROR Name to long", $strFirstName & " can't be over 20 characters." & @CRLF & "Total: " & $len)         ;Exit         GUIDelete($Form1)     EndIf Until $len < "20" MsgBox(0, "Done", "")  
    • mrtgtr
      By mrtgtr
      I want to do something , after wait 2 min and again do same thing
      But I do do not want with sleep, it must be timer 
      How I do this ?
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • 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 -.-'
×