Jump to content
Sign in to follow this  
junia

reading file names

Recommended Posts

junia

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.

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
junia

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

Share this post


Link to post
Share on other sites
junia

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
junia

That is exactly what i was trying to do.

Thank You soo much for your quick response.

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  

×