Lasso Soft Inc. > Home

[ dir->forEachEntry ]

Method

The [dir->forEachEntry] 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 [pair] whose first element is the name of the item and whose second element is an integer which flags the item as a file, folder, symbolic link, etc.

  • Syntax
local(d) = dir(...)
#d->forEachEntry => {
    #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