Lasso Soft Inc. > Home

[ dir->forEach ]

Method

The [dir->forEach] method takes a block of code that will be executed for each item in the folder the [dir] object refers to. Inside the block you can access the current item using the special local variable #1 which will be a string containing the name of the item. (Names of directories will have a trailing slash.)

  • Syntax
local(d) = dir(...)
#d->forEach => {
    #1
}
Examples
  • Intermediate

List the items in web-root

The code below will display the list of items in the web root as an un-ordered list. For purposes of the result, assume the web-root contains the following items:  'css/', 'img/', 'index.lasso', 'js/', and 'test.lasso'

Code

local(web_root) = dir('/')
'<ul>'
#web_root->forEachEntry => {^
    '<li>' + #1->first + '</li>'
^}
'</ul>'

Result

  • css/
  • img/
  • index.lasso
  • js/
  • test.lasso

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 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft