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

Create a new stack and drag on basic components

Start by creating a new stack and drag on a button for our script and a field to hold our list of files.

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

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.

on mouseUp

# 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

exit mouseUp

end if

# 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

end mouseUp

1 Comments

Tim Franklin

Nice, out of curiosity, how would one go about designing a, directory structure that could be navigated, thanks for taking time to post.

Add your comment

E-Mail me when someone replies to this comment