Lasso Soft Inc. > Home

[ dir->each ]

Method

The [dir->each] method returns an object which contains each file and directory contained in the directory that the [dir] object represents.

  • Syntax
local(d) = dir(...)
#d->each
Examples
  • Intermediate

Count the number of files and directories in web-root

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

Recent Comments

No Comments found

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. > Home

 

 

©LassoSoft Inc 2014 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft