Filesystem Module

From SolarStrike wiki
Jump to: navigation, search


string filesystem.getFileName(string path)

Returns just the filename (no path) section of a full path.


string filesystem.getFilePath(string path)

Returns just the path (no filename) section of a full path. Does not include trailing slash (/).


boolean filesystem.directoryExists(string path)

If the given directory exists, returns true. Else, returns false.


boolean filesystem.fileExists(string path)

If the given file exists, returns true. Else, returns false.


table filesystem.getDirectory(string path)

If the given directory does not exist or contains no files, this function fails. Otherwise, returns a table of filenames & directories contained in this path. This does not include "." and ".."


boolean filesystem.isDirectory(string path)

If the given path is a directory, returns true. Else, returns false.


boolean filesystem.createDirectory(string path)

Creates a directory at 'path'. This function is recursive and will create additional directories as necessary. Returns true on success, else false.


string filesystem.fixSlashes(string path[, boolean posix])

Convert slashes within 'path' to / (POSIX standard) or \ (Windows only).

If posix is true (default), converts backslashes(\) to forward slashes(/). Else, converts forward slashes to backslashes.


string filesystem.getOpenFileName(string defaultFilename[, string filter])

Displays the standard open file dialog. 'defaultfilename' can contain a full path to the default file. 'filter' should be properly formatted: Split key/value pairs with NULL (\0), terminate with double NULL(\0\0). Multiple filetypes should be split with semicolon (;). For example:

filter = "All Files\0*.*\0Lua files\0*.lua\0Image files\0*.bmp;*.jpg\0\0";
filesystem.getOpenFileName("", filter);

If the user cancels the dialog, this function fails and returns nil.


string filesystem.getSaveFileName(string defaultFilename[, string filter])

This works exactly like filesystem.getOpenFileName() except that it shows the dialog for saving a file.


string filesystem.getCWD()

Returns the current working directory. This should be the directory that MicroMacro is currently executing a script from.



Modify the current working directory (CWD) to the given path. You probably don't want to do this under normal conditions.