junia Posted November 18, 2009 Share Posted November 18, 2009 I'm building a media center like in windows 7 to manage my video files over my home network & I'm having issues reading the file names in my folders. What I'm trying to do is find a control that will read the file names in a specific folder then would return the filename value so that i can use the filename as the text on my button to select the file i want to play. So far all i've been able to come up with was using "_FileListToArray" to create a array, then use "_FileWriteFromArray" to create a txt file with all the file names in it. Then save the txt file so that i can use "FileReadLine" to read the the line of text to put it as the value of the button. This is a extremelly long script that i find is not efficient at all so any suggestions would be greatly appreciated. Link to comment Share on other sites More sharing options...
water Posted November 18, 2009 Share Posted November 18, 2009 (edited) Why don't you simply access the values in the array? Example: #include <GUIConstantsEx.au3> Global $asArray[2] = ["File1","file2"] ; Could be filled by _FileListToArray Local $msg GUICreate("My GUI") $Button = GUICtrlCreateButton("Test", -1, -1, 200, 50) GUISetState() Sleep(2000) GUICtrlSetData($Button,$asArray[0]) Sleep(2000) GUICtrlSetData($Button,$asArray[1]) ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Edited November 18, 2009 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
junia Posted November 18, 2009 Author Share Posted November 18, 2009 Thank you so much. I just gave it a quick try and it seemed to have worked. I'll finish my script tonight & post it. Thanks Again Link to comment Share on other sites More sharing options...
junia Posted November 19, 2009 Author Share Posted November 19, 2009 I've got my script working now. But the problem i'm having is with the error codes. If the folder I'm reading the file names from only has 3 files in it the script will crash when reading from the 4th array. What kind of error handling code can i put in here as i will be adding files to these folders everyweek & i want the array to update itself when i start the program. Example.au3 Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 19, 2009 Share Posted November 19, 2009 (edited) Time to learn the joys of event mode GUIs: expandcollapse popup#include <GUIConstantsEx.au3> #Include <File.au3> #include <Array.au3> Opt("GuiOnEventMode", 1) Global $asArray, $iWidth, $iHeight, $aButtons[1], $iX, $iY, $msg $asArray = _FileListToArray(@DesktopDir) If @error Then Exit $iWidth = 300 $iHeight = ($asArray[0] * 40) + 20 $iX = 10 ReDim $aButtons[UBound($asArray)] $aButtons[0] = $asArray[0] GUICreate("My GUI", $iWidth, $iHeight) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") For $n = 1 To $asArray[0] $iY = 10 + (($n - 1) * 40) $aButtons[$n] = GUICtrlCreateButton($asArray[$n], $iX, $iY, $iWidth - ($iX * 2), 30) GUICtrlSetOnEvent(-1, "_ButtonHit") Next GUISetState() While 1 Sleep(10) WEnd Func _ButtonHit() Local $sText = GUICtrlRead(@GUI_CtrlId) MsgBox(64, "Button Hit", "You clicked: " & $sText, 3) EndFunc Func _Quit() Exit EndFunc Note that the control IDs of all the buttons are there in an array if you need them (i.e. maybe loop through them to change colors), but aren't used anywhere in this script. The event function _ButtonHit() receives the ID in the macro @GUI_CtrlID. So you could delete all references to $aButtons and not save the control IDs at all and the GUI would still work perfectly. Edited November 19, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
junia Posted November 19, 2009 Author Share Posted November 19, 2009 That is exactly what i was trying to do. Thank You soo much for your quick response. 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