Difference between revisions of "Fs.combine"

From ComputerCraft Wiki
Jump to: navigation, search
m (Moved to CAT:LuaCoreFunctions)
(Copy description from API page and use type template)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
 
{{Function
 
{{Function
 
|name=fs.combine
 
|name=fs.combine
|args=[[string (type)|string]] basePath, [[string(type)|string]] localPath
+
|args={{Type|string}} basePath, {{Type|string}} localPath
 
|api=fs
 
|api=fs
|returns=[[string]] the combined path
+
|returns={{Type|string}} the combined path
|desc=Combines two paths, such that the new path consists of all the components of <var>localPath</var> inside all the components of <var>basePath</var> (neither path needs to exist; this function only manipulates strings and does not touch the filesystem)
+
|desc=Combines two path components, returning a path consisting of the local path nested inside the base path. The resultant path consists of all the components of <var>localPath</var> inside all the components of <var>basePath</var>. Neither path needs to exist; this function only manipulates strings and does not touch the filesystem.
 
|examples=
 
|examples=
 
{{Example
 
{{Example

Latest revision as of 19:43, 22 April 2013


Grid Redstone.png  Function fs.combine
Combines two path components, returning a path consisting of the local path nested inside the base path. The resultant path consists of all the components of localPath inside all the components of basePath. Neither path needs to exist; this function only manipulates strings and does not touch the filesystem.
Syntax fs.combine(string basePath, string localPath)
Returns string the combined path
Part of ComputerCraft
API fs

Examples

Grid paper.png  Example
Computes the absolute path to a file called "d" inside a directory called "c", where "c" is itself inside a directory "b" which is inside a directory "a"
Code
print(fs.combine("a/b", "c/d"))
Output a/b/c/d



Grid paper.png  Example
An empty first path refers to the root directory, so the second path is returned
Code
print(fs.combine("", "c/d"))
Output c/d



Grid paper.png  Example
An empty second path refers to the first path directly, so the first path is returned
Code
print(fs.combine("a/b", ""))
Output a/b



Grid paper.png  Example
The last two examples make sense combined, returning the empty string (referring to the root directory)
Code
print(fs.combine("", ""))