Lasso Soft Inc. > Home

[js_directorytree]

Linkjs_directorytree
AuthorJohan Solve
CategoryFile
Version8.x
LicensePublic Domain
Posted19 Mar 2008
Updated19 Mar 2008
More by this author...

Description

The tag returns an array of all paths of a directory tree, in other words a directory listing including all sub directories.

It can optionally return a map instead of an array, useful when creating a faster replacement for file_exists.

Sample Usage

js_directorytree('/config');
Returns 
array: (/_config/.DS_Store), (/_config/config.inc), (/_config/config_tabs.inc)

js_directorytree('/config', -type='map');
Returns
map: (/_config/config_tabs.inc)=(), (/_config/.DS_Store)=(), (/_config/config.inc)=()

if(global('allfiles') -> type != 'map');
    global('allfiles'=js_directorytree('/', -type='map')); // call this only once
/if;
$allfiles >> '/includes/menu.inc';
Returns true or false

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag('directorytree',
	-namespace='js_',
	-required='path',
	-optional='type', -copy,
	-optional='recursive' /* for internal use only */);
	!(#path -> endswith('/')) ? #path += '/';
	local('type') != 'map' ? local('type'=array); 
	local('dirlist'=(#type=='map' ? map | array),
		'diritem'=string,
		'dirlist_sub'=(#type=='map' ? map | array),
		'diritem_sub'=pair,
		'toplevel'=!local_defined('recursive'));
	iterate(file_listdirectory(#path), #diritem);
		#dirlist_sub = (#type=='map' ? map | array);
		if(#diritem -> endswith('/'));
			// recursive call for sub folder within the media directory structure
			#dirlist_sub = js_directorytree(#path + #diritem, -type=#type, -recursive);
			iterate(#dirlist_sub, #diritem_sub);
				#dirlist -> insert((#toplevel ? #path)  + #diritem + (#type == 'map' ? #diritem_sub -> name | #diritem_sub));
			/iterate;
		else;
			// add non-folders to list
			#dirlist -> insert((#toplevel ? #path) + #diritem);
		/if;
	/iterate;
	return(#dirlist);
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

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