[directory_tree]

Description

Link: [directory_tree]
Author: Jason Huck
Category: File
Version: 8.5.x
License:
Posted: Feb. 27, 2007
Updated: Jan. 01, 0001
More by this author...
This is a recursive directory crawler that outputs nested unordered lists. You can specify lists of file extensions to include or exclude from crawling. It requires all the same permissions as the built-in file tags.

Parameters

-path string, required A valid path to a directory.
-include array, optional A list of file extensions to include.
-exclude array, optional A list of file extensions to exclude.
-hidden boolean, optional Whether to include hidden files/folders. Defaults to false.
-depth integer, optional Tab depth to start from for HTML output. Defaults to zero.

Sample Usage

inline(
	-username='xxxxxx',
	-password='xxxxxx'
);
	var('list') = directory_tree(
		'/ExamplesPack/',
		-include=(: 'js'),
		-exclude=(: 'php'),
		-hidden=false
	);
/inline;
						

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
define_tag(
	'tree',
	-namespace='directory_',
	-req='path',
	-opt='include', -type='array',
	-opt='exclude', -type='array',
	-opt='hidden', -type='boolean',
	-opt='depth', -type='integer',
	-priority='replace',
	-description='Returns nested unordered lists of files/folders within the given path.'
);
	fail_if(
		!file_isdirectory(#path),
		-1,
		'The path supplied is not a directory.'
	);
	
	local('out') = string;
	!local_defined('include') ? local('include') = array;
	!local_defined('exclude') ? local('exclude') = array;
	!local_defined('hidden') ? local('hidden') = false;
	!local_defined('depth') ? local('depth') = 0;
	
	#depth == 0 ? #out += '<h6><a href="' + #path + '">' + string(#path)->removetrailing('/')&split('/')->last + '</a></h6>\n';
	#out += ('\t' * #depth) + '<ul>\n';
	local('list') = file_listdirectory(#path);

	iterate(#list, local('i'));		
		(#i->beginswith('.') && !#hidden) ? loop_continue;
		local('ext') = (#i >> '.' ? #i->split('.')->last | '');				
		#out += ('\t' * (#depth + 1)) + '<li>';
			
		if(file_isdirectory(#path + #i));
			#out += '\n' + ('\t' * (#depth + 2)) + '<a href="' + (#path + #i) + '">' + #i + '</a>\n' + directory_tree(
				#path + #i,
				-include=#include,
				-exclude=#exclude,
				-hidden=#hidden,
				-depth=(#depth + 2)
			);
			
			#out += ('\t' * (#depth + 1)) + '</li>\n';
		else;
			(!#include->size || #include >> #ext) && (!#exclude->size || #exclude !>> #ext) ? #out += '<a href="' + (#path + #i) + '">' + #i + '</a></li>\n';
		/if;
	/iterate;
	
	local('out') += ('\t' * #depth) + '</ul>\n';
	return(#out);
/define_tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular