MTA:Eir/FileSystem/translator/chdir
Jump to navigation
Jump to search
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 [-]
ClientThis 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 );