Jump to content

reading file names


junia
 Share

Recommended Posts

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

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 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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Time to learn the joys of event mode GUIs:

#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 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...