Retrieve file list from web directory
The following explains one method to extract a file list from an online web directory.
n.b. In this lesson we will be retrieving a list from an "on-rev" web directory. There may be slight differences when retrieving the data from different web hosts
Create and Setup new Stack
1) Give the stack a name
2) Add a scrolling list field called "data". Set its text to centre and increase the font size
3) Add a button and set its label to "get file list"
View initial source of directory
We will want to use the source data of our web directory in order to extract the required data from it. We can view the source data of the following test site by executing the following script in the message box.
(Suppose there is a directory "VideoAssets" in your server)
put url "http://path/to/your/server/VideoAssets/" into field "data"
From the above screen, you can see that the source includes a lot of data that we dont need. The next step will cover how to remove this and extract the data that we need
Extracting the data
Add the following script to your button-
on mouseUp put url ("http://path/to/your/server/VideoAssets/") into tURL put empty into field "data" delete line 1 to 8 of tURL delete line -3 to -1 tURL set the itemdel to quote repeat with x = 1 to the number of lines of tURL put item 6 of line x of tURL into tData put cr after tData put tData after field "data" end repeat replace "%20" with space in field "data" end mouseUp
A breakdown of this script is-
1) Acquires the source
2) Clear any existing data from the field
3) Removes any non-needed lines of text
4) We set the item delimiter to quote
5) Set up a repeat look to loop through the lines of the remaining text and place the desired item into field "data". As the item delimiter is quote, then item 6 of each line is the list we need
6) The list will contain "%20" where spaces should be, so replacing these with spaces makes things more aesthetically pleasing.
The result of this script can be seen above.
As this is a list field, the data associated with the selected line can be retrieved with the following script:
put the selectedText of field "data"