Lasso Soft Inc. > Home

[lp_file_trimPath]

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

Description

Returns a sanitized path that will never specify from harddisk root.

Requires [lp_string_split]

Sample Usage

'
';
var:'paths' = (: 
	'/this/that     ',
	'  /this/ that/ ',
	'//this//../that//',
	'///this/that/  ',
	'c://somedir/  ',
	' c:\\this\\that\\',
	'/this/somefile.txt',
	'c://somedir/this/somefile.txt'
	);

iterate: $paths, local:'path';
	'"' #path '"';
	'\t';
	'"' (lp_file_trimpath:#path) '"';
	'\r\n';
/iterate;
'
'; Returns: "/this/that " "/this/that" " /this/ that/ " "/this/that/" "//this//../that//" "/this/that/" "///this/that/ " "/this/that/" "c://somedir/ " "/somedir/" " c:\this\that\" "/this/that/" "/this/somefile.txt" "/this/somefile.txt" "c://somedir/this/somefile.txt" "/somedir/this/somefile.txt"

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_trimPath',
	-description='Returns a sanitized path that will never specify from harddisk root.',
	-priority='replace',
	-required='path';
	
	local:'newpath' = (string: #path);
	#newpath->(replace:'\\','/');
	if: #newpath->(contains:':');
		#newpath = (lp_string_split: #newpath, ':', 2)->(get:2);
	/if;
	#newpath = (string_replaceregexp: #newpath, -find="[^a-z0-9\\/\\!\\@\\#\\$\\%\\^\\&\\(\\)\\{\\}\\-\\=\\_\\+\\~\\`\\;\\'\\,\\.]", -replace='', -ignorecase);
	#newpath = (string_replaceregexp: #newpath, -find="\\.\\.+", -replace='..', -ignorecase);
	#newpath = (string_replaceregexp: #newpath, -find="/+", -replace='/', -ignorecase);
	return: #newpath;

]

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