Lasso Soft Inc. > Home

[lp_file_findPath]

Linklp_file_findPath
AuthorBil Corry
CategoryFile
Version8.5.x
LicensePublic Domain
Posted02 Sep 2006
Updated02 Sep 2006
More by this author...

Description

Returns the web path (or null) to the first found file or directory that matches the given name starting from the current path up to the webroot.

Requires [lp_page_path]

Sample Usage

	'dir path: '; lp_file_findPath:'folder';'
'; 'file path: '; lp_file_findPath:'file.lasso';'
'; 'dir fullpath: '; lp_file_findPath:'folder',-fullpath;'
'; 'file fullpath: '; lp_file_findPath:'file.lasso',-fullpath;'
'; 'dir fullpath -file: '; lp_file_findPath:'folder',-fullpath,-file;'
'; 'file fullpath -file: '; lp_file_findPath:'file.lasso',-fullpath,-file;'
'; 'dir fullpath -dir: '; lp_file_findPath:'folder',-fullpath,-dir;'
'; 'file fullpath -dir: '; lp_file_findPath:'file.lasso',-fullpath,-dir;'
';

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:'lp_file_findPath',
	-description='Returns the web path (or null) to the first found file or directory that matches the given name starting from the current path up to the webroot.',
	-privileged,
	-priority='replace',
	-required='name',-copy,
	-optional='file',		// boolean, -file means find only a file
	-optional='folder',		// boolean, -folder means find only a directory
	-optional='dir',		// boolean, -dir means find only a directory
	-optional='directory',	// boolean, -directory means find only a directory
	-optional='fullPath';	// boolean, -fullpath returns the path including the file/directory found

	// make sure #name is string
	#name = (string: #name);
	#name->(removeleading:'/');
	#name->(removetrailing:'/');
	
	// current path as array
	local:'path' = lp_page_path->folderlist;

	// find a file?
	if: (local_defined:'file');
		local:'file' = true;
	else;
		local:'file' = false;
	/if;

	// find a directory?
	if: (local_defined:'folder') || (local_defined:'directory') || (local_defined:'dir');
		local:'dir' = true;
	else;
		local:'dir' = false;
	/if;

	// default is to find both, whichever is found first
	if: !#file && !#dir;
		#file = true;
		#dir = true;
	/if;

	// return fullpath?
	if: (local_defined:'fullPath');
		local:'fullPath' = true;
	else;
		local:'fullPath' = false;
	/if;
	
	local:'lastOne' = true;
	while: #path->size || #lastOne;
	
		// webroot is last one
		if: #path->size == 0 && #lastOne;
			#lastOne = false;
		/if;

		if: #file;

			if: (file_exists:('/' #path->(join:'/') '/' #name)) && !(file_isDirectory:('/' #path->(join:'/') '/' #name));
				if: #fullPath;
					return: '/' #path->(join:'/') '/' #name;
				else;
					return: '/' #path->(join:'/') '/';
				/if;
			/if;
		/if;
		
		if: #dir;

			if: (file_exists:('/' #path->(join:'/') '/' #name '/')) && (file_isDirectory:('/' #path->(join:'/') '/' #name '/'));
				if: #fullPath;
					return: '/' #path->(join:'/') '/' #name '/';
				else;
					return: '/' #path->(join:'/') '/';
				/if;
			/if;		
		
		/if;

		#path->remove; // remove last element
	/while;

	// if got here, didn't find it
	return: null;
	
/define_tag;

]

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