[js_directorytree]

Description

Link: [js_directorytree]
Author: Johan Sölve
Category: File
Version: 8.x
License: Public Domain
Posted: Mar. 19, 2008
Updated: Mar. 19, 2008
More by this author...
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.

Parameters

-path string, required The name of the directory to be listed
-type string, optional The name of the data type to return. Can be 'map' or 'array, defaults to 'array'

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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

none

Email:


Password:



Newest

Most Popular