Catalyst159 Posted August 18, 2010 Share Posted August 18, 2010 I am basically listing all the files in a directory in a listbox. The problem I am having is that the files I want listed in the listbox are in a folder that is within the @ScriptDir. Does anyoner know how I can specify the path to this folder. I have tried _PathFull(@ScriptDir & "\decks"). This did not work. No errors are reported but nothing is listed in the listbox. The folder that contains the files I need to be displayed in the list box is called "decks". It is in the directory where the script resides. Any help would be greatly appreciated. The following is part of the autoIT SCRIPT: expandcollapse popupFunc Index() $Folder = @ScriptDir $Search = FileFindFirstFile($Folder & '\*.*') While 1 $File = FileFindNextFile($Search) If @error Then ExitLoop $Attr = FileGetAttrib($File) If Not @error And StringInStr($Attr, 'D') = 0 Then $Data = $Data & '|' & $File EndIf WEnd FileClose($Search) $Data = StringLeft($Data, StringLen($Data) - 1);remove last separator $Data = StringRight($Data, StringLen($Data) - 1);remove first separator ConsoleWrite($Data & @CRLF); Debug Data (Output) EndFunc ;==>Index Func Search() $savetext = GUICtrlRead($input) For $i = 1 To $Split[0] If GUICtrlRead($Case) = $GUI_CHECKED Then If StringLeft($Split[$i], StringLen(GUICtrlRead($input))) == $savetext Then $buffer &= $Split[$i] & "|" EndIf Else If StringLower(StringLeft($Split[$i], StringLen(GUICtrlRead($input)))) == StringLower($savetext) Then $buffer &= $Split[$i] & "|" EndIf EndIf Next $buffer = StringTrimRight($buffer, 1) GUICtrlSetData($list, "") GUICtrlSetData($list, $buffer) $buffer = "" EndFunc ;==>Search Link to comment Share on other sites More sharing options...
boogieoompa Posted August 18, 2010 Share Posted August 18, 2010 (edited) Here is some code from my script/scraps file. More includes than you need but w/e. Hope this helps #include <GUIConstants.au3> #Include <File.au3> #Include <Array.au3> #Include <GUIComboBox.au3> #include <GUIConstantsEx.au3> #include <String.au3> opt("GUIOnEventMode", 1) $maingui = GUICreate("Test", 500, 500, 1, 1) $btnmain = GUICtrlCreateButton("Click on me", 250, 10, 100, 25) $lstmain = GUICtrlCreateList("",10,40,220,700) GUICtrlSetOnEvent($btnmain,"FunRead") GUISetState() While 1 sleep(100) WEnd Func FunRead() Global $FileList=_FileListToArray(@ScriptDir, "*.txt") Select Case @error = 1 MsgBox (0,"","Error with finding directory!") Exit Case @error = 4 MsgBox (0,"","No Files Found.") Case Else $max = UBound($FileList) $i = 1 While $i < $max GUICtrlSetData($lstmain, $filelist[$i]) $i = $i+1 WEnd EndSelect EndFunc Edited August 19, 2010 by boogieoompa Link to comment Share on other sites More sharing options...
Catalyst159 Posted August 19, 2010 Author Share Posted August 19, 2010 The script you provided was very helpful and resourceful. But how can I specify a path that is different than the @ScriptDir. From my understanding, @ScriptDir represents the active scripting directory where your script file is right ? But what if I need to specify the path of a folder that is within the @ScriptDir. I appreciate any help. Thank you. Link to comment Share on other sites More sharing options...
omikron48 Posted August 19, 2010 Share Posted August 19, 2010 (edited) This? $search = FileFindFirstFile(@ScriptDir & "\decks\*") If $search <> -1 Then ;if first file found While 1 $File = FileFindNextFile($search) If @error = 1 Then ExitLoop If @extended = 1 Then ;if folder $Data &= '|' & $File EndIf WEnd FileClose($search) EndIf Edited August 19, 2010 by omikron48 Link to comment Share on other sites More sharing options...
Catalyst159 Posted August 19, 2010 Author Share Posted August 19, 2010 Is this a suggestion to try ? & "\decks\*") What is the * doing for us here ? Link to comment Share on other sites More sharing options...
omikron48 Posted August 19, 2010 Share Posted August 19, 2010 (edited) It's a filter to include everything inside the specified folder. The FileFind* functions aren't recursive, which mean that they don't search subdirectories by themselves. The example you posted only searches the files located in @ScriptDir. You have to explicitly tell it to search the subfolder you want to search there. $Folder = @ScriptDir $Search = FileFindFirstFile($Folder & '\*.*') This means to search the folder specified by @ScriptDir. Edited August 19, 2010 by omikron48 Link to comment Share on other sites More sharing options...
boogieoompa Posted August 19, 2010 Share Posted August 19, 2010 Easy enough... just change the @scriptdir to your file path, but you have to reference it like a string so you have to include the path in "". If you want to recurse further into your directory than its @scriptdir & "subfolder" I dont think you have to put "\subfolder" but I'm too lazy to alt tab to try it lol. Cheers #include <GUIConstants.au3> #Include <File.au3> #Include <Array.au3> #Include <GUIComboBox.au3> #include <GUIConstantsEx.au3> #include <String.au3> opt("GUIOnEventMode", 1) $maingui = GUICreate("Test", 500, 500, 1, 1) $btnmain = GUICtrlCreateButton("Click on me", 250, 10, 100, 25) $lstmain = GUICtrlCreateList("",10,40,220,700) GUICtrlSetOnEvent($btnmain,"FunRead") GUISetState() While 1 sleep(100) WEnd Func FunRead() Global $FileList=_FileListToArray("C:\Ben", "*.txt") Select Case @error = 1 MsgBox (0,"","Error with finding directory!") Exit Case @error = 4 MsgBox (0,"","No Files Found.") Case Else $max = UBound($FileList) $i = 1 While $i < $max GUICtrlSetData($lstmain, $filelist[$i]) $i = $i+1 WEnd EndSelect EndFunc Link to comment Share on other sites More sharing options...
Catalyst159 Posted August 21, 2010 Author Share Posted August 21, 2010 Ok I will try that and post results. Thanks. Link to comment Share on other sites More sharing options...
Catalyst159 Posted August 23, 2010 Author Share Posted August 23, 2010 Hey all, This is what ended up working for me: expandcollapse popupFunc FunRead() Local $nmsg Global $FileList = _FileListToArray("decks", "*.pdf") Select Case @error = 1 MsgBox(0, "", "Error with finding directory!") Exit Case @error = 4 MsgBox(0, "", "No Files Found.") Case Else $max = UBound($FileList) $i = 1 While $i < $max GUICtrlSetData($lstmain, $FileList[$i]) $i = $i + 1 WEnd EndSelect Do $nmsg = GUIGetMsg() Until $nmsg = $GUI_EVENT_CLOSE EndFunc ;==>FunRead I would like to thank boogieoompa and omikron48 for all there help. It is greatly appreciated. Link to comment Share on other sites More sharing options...
omikron48 Posted August 24, 2010 Share Posted August 24, 2010 (edited) Just to help improve your coding. If you have something like this: $max = UBound($FileList) $i = 1 While $i < $max GUICtrlSetData($lstmain, $FileList[$i]) $i = $i + 1 WEnd and the $i isn't used for much anything else other than counting, not calculated from something else, it's much better to use a For..Next loop in that situation like so: For $i = 1 To UBound($FileList) - 1 GUICtrlSetData($lstmain, $FileList[$i]) Next Edited August 24, 2010 by omikron48 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now