Lasso Soft Inc. > Home

[directory_tree]

Linkdirectory_tree
AuthorJason Huck
CategoryFile
Version8.5.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted27 Feb 2007
Updated27 Feb 2007
More by this author...

Description

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.

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.

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 += '
' + string(#path)->removetrailing('/')&split('/')->last + '
\n'; #out += ('\t' * #depth) + '
    \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)) + '
  • '; if(file_isdirectory(#path + #i)); #out += '\n' + ('\t' * (#depth + 2)) + '' + #i + '\n' + directory_tree( #path + #i, -include=#include, -exclude=#exclude, -hidden=#hidden, -depth=(#depth + 2) ); #out += ('\t' * (#depth + 1)) + '
  • \n'; else; (!#include->size || #include >> #ext) && (!#exclude->size || #exclude !>> #ext) ? #out += '' + #i + '\n'; /if; /iterate; local('out') += ('\t' * #depth) + '
\n'; return(#out); /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