Modules/FileSystem/translator/chdir: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ This function changes the current directory pointer of the translator. All operations on the FileSystem translator are executed relative to the current directory. The translator, if possible, is asked to prevent deletion of the current directory. ==Syntax== <syntaxhighlight lang="lua"> bool translator:chdir ( string dirPath ) </syntaxhighlight> ==Arguments== *'''dirPath:''' a path to a directory that should be made current directory ==Returns== This functio...")
 
No edit summary
 
Line 1: Line 1:
<pageclass class="#3c82c8" subcaption="Translator function"></pageclass>
__NOTOC__
__NOTOC__
This function changes the current directory pointer of the translator. All operations on the FileSystem translator are executed relative to the current directory. The translator, if possible, is asked to prevent deletion of the current directory.
This function changes the current directory pointer of the translator. All operations on the FileSystem translator are executed relative to the current directory. The translator, if possible, is asked to prevent deletion of the current directory.

Latest revision as of 03:25, 23 January 2022

This function changes the current directory pointer of the translator. All operations on the FileSystem translator are executed relative to the current directory. The translator, if possible, is asked to prevent deletion of the current directory.

Syntax

bool translator:chdir ( string dirPath ) 

Arguments

  • dirPath: a path to a directory that should be made current directory

Returns

This function returns true if the directory pointed at by dirPath is an existing directory and can be accessed by the translator, false otherwise.

Example

Click to collapse [-]
Client

This snippet creates a simple command-based filesystem explorer.

-- Create a generic FileSystem translator.
local cmdTranslator = fileCreateTranslator( "/" );

-- Set up some commands.
addCommandHandler( "chdir",
    function(...)
        local myPath = table.concat( { ... }, " " );

        cmdTranslator:chdir( myPath );
    end
);

addCommandHandler( "dir",
    function()
        -- todo: resolve a path given as arguments.

        local myEntries = {};

        local function itemIterator( path )
            table.insert( myEntries, cmdTranslator:relPath( path ) );
        end

        cmdTranslator:scanDirEx( "/", "*", itemIterator, itemIterator, false );

        -- Output the filesystem entries to the chatbox.
        for m,n in ipairs( myEntries ) do
            outputChatBox( n );
        end

        -- todo: print statistics (file size, number of files, number of directories, ...)
    end
);

FileSystem Translator Functions