How to list the files in a folder
This lesson will show you how to get a list of all the files in a specific folder.
Create a new stack and drag on basic components
Key lines of code
The following lines of code are the key items we need for this particular task. The 'defaultfolder' is where Revolution looks when you perform file or folder requests. So if we set the 'defaultfolder' to where our files are we will be able to ready them very easily.
set the defaultfolder to tFolderPath
The second key line of code required is this one. It will return a list of all the files in the 'defaultfolder'.
put the files
Put them into practice
Edit the script of the button by selecting it (1) and clicking on the script icon in the toolbar (2). Paste the following script into the script window and click compile. When you click on the button, a dialog should popup asking you to select a folder. All the files in the folder you select will be listed in the text field.
# Pops up a dialog box letting the user select a folder
answer folder "Please select a folder"
# Exit this handler if the user click cancel on the dialog
if it is "cancel" then
# Set the default folder to the folder selected by the user
# (this is stored in the 'it' variable
set the defaultfolder to it
# Put a list of all the files in field 1
put the files into field 1