[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.
Requires [lp_page_path]
Parameters
-name
string, required
Name of file or directory to find.
-file
boolean, optional
Find only a file.
-folder
boolean, optional
Find only a directory.
-directory
boolean, optional
Find only a directory.
-dir
boolean, optional
Find only a directory.
-fullpath
boolean, optional
Return path found with file/dir name included.
Sample Usage
'dir path: '; lp_file_findPath:'folder';'<br>';
'file path: '; lp_file_findPath:'file.lasso';'<br>';
'dir fullpath: '; lp_file_findPath:'folder',-fullpath;'<br>';
'file fullpath: '; lp_file_findPath:'file.lasso',-fullpath;'<br>';
'dir fullpath -file: '; lp_file_findPath:'folder',-fullpath,-file;'<br>';
'file fullpath -file: '; lp_file_findPath:'file.lasso',-fullpath,-file;'<br>';
'dir fullpath -dir: '; lp_file_findPath:'folder',-fullpath,-dir;'<br>';
'file fullpath -dir: '; lp_file_findPath:'file.lasso',-fullpath,-dir;'<br>';
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
[
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
none
Newest
Most Popular