The [dir->each]
method returns an object which contains each file and directory contained in the directory that the [dir]
object represents.
local(d) = dir(...)
#d->each
The code below loops through the contents of the web-root folder and counts the number of files and the number of directories it contains. For the example, assume that the directory contains the following contents: 'css/', 'img/', 'index.lasso', 'js/', and 'test.lasso'
Code
local(web_root) = dir('/')
local(num_files) = 0
local(num_dirs) = 0
with d in #web_root->each
do {
#d->type == 'file' ? #num_files += 1 | #num_dirs += 1
}
'Number of Files: ' + #num_files
'<br>'
'Number of Folders: ' + #num_dirs
Result
Number of Files: 2
Number of Folders: 3
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
Recent Comments