MTA:Eir/FileSystem/translator/relPathRoot: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ This function transform a path that is passed to it into a path that is relative to the translators root directory. The path must be accessible from the translator. The...")
 
mNo edit summary
 
Line 4: Line 4:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string translator.relPathRoot ( string path )
string translator:relPathRoot ( string path )
</syntaxhighlight>
</syntaxhighlight>


Line 21: Line 21:


-- Change into another directory.
-- Change into another directory.
resRoot.createDir( "myDir/" );
resRoot:createDir( "myDir/" );
resRoot.chdir( "myDir/" );
resRoot:chdir( "myDir/" );


-- Output the path relative to the current directory and relative to the translator root directory.
-- Output the path relative to the current directory and relative to the translator root directory.
local thePath = "someDir/../myFile.txt";
local thePath = "someDir/../myFile.txt";
local relativeToCurrent = resRoot.relPath( thePath );
local relativeToCurrent = resRoot:relPath( thePath );
local relativeToRoot = resRoot.relPathRoot( thePath );
local relativeToRoot = resRoot:relPathRoot( thePath );


outputChatBox( "input-path: " .. thePath );
outputChatBox( "input-path: " .. thePath );

Latest revision as of 23:26, 16 January 2022

This function transform a path that is passed to it into a path that is relative to the translators root directory. The path must be accessible from the translator. The path can either be absolute or relative.

Syntax

string translator:relPathRoot ( string path )

Arguments

  • path: the path that should be transformed into a relative path; can be nil to return the null path

Returns

This function returns the relative version of the path that is passed to it, false if the specified path is not accessible by the translator.

Example

Click to collapse [-]
Client

This snippet returns the relative-to-root version of a translator relative path.

-- Create a generic file translator to the resource instance directory.
local resRoot = fileCreateTranslator( "/" );

-- Change into another directory.
resRoot:createDir( "myDir/" );
resRoot:chdir( "myDir/" );

-- Output the path relative to the current directory and relative to the translator root directory.
local thePath = "someDir/../myFile.txt";
local relativeToCurrent = resRoot:relPath( thePath );
local relativeToRoot = resRoot:relPathRoot( thePath );

outputChatBox( "input-path: " .. thePath );
outputChatBox( "relative-to-current: " .. relativeToCurrent );
outputChatBox( "relative-to-root: " .. relativeToRoot );

FileSystem Translator Functions