Filesystem Module
#filesystem.getFileName string filesystem.getFilename(string fullpath)

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

Example:
local path = "C:\\micromacro\\scripts\\test.lua"; print(filesystem.getFileName(path)); -- This should print "test.lua" to the console
#filesystem.getFilePath string filesystem.getFilePath(string fullpath)

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

Example:
local path = "C:\\micromacro\\scripts\\test.lua"; print(filesystem.getFilePath(path)); -- This should print "C:\micromacro\scripts" to the console
#filesystem.directoryExists boolean filesystem.directoryExists(string path)

If the given directory specified by 'path' exists, this function returns true, otherwise it will return false.

#filesystem.fileExists boolean filesystem.fileExists(string path)

If the given file specified by 'path' exists, this function returns true, otherwise it will return false.

#filesystem.getDirectory table filesystem.getDirectory(string path)

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

The returned table does not distinguish between files and directories. You may wish to iterate over the table and check them independently using filesystem.isDirectory()

Example code:
table.print(filesystem.getDirectory('C:/micromacro'));
Example output:
1: "alut.dll" 2: "config.default.lua" 3: "config.lua" 4: "lib" 5: "libncurses5.dll" 6: "license.txt" 7: "logs" 8: "lua53.dll" 9: "micromacro.exe" 10: "OpenAL32.dll" 11: "scripts" 12: "sqlite3.dll" 13: "src"
#filesystem.isDirectory boolean filesystem.isDirectory(string path)

If the given 'path' is a directory, this function returns true. Otherwise, this function returns false.

#filesystem.createDirectory boolean filesystem.createDirectory(string path)

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

#filesystem.fixSlashes string filesystem.fixSlashes(string path) string filesystem.fixSlashes(string path, boolean posix)

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

If 'posix' is true (default), it converts backslashes(\) to forward slashes(/). If 'posix' is false, this function converts forward slashes to backslashes.

#filesystem.getOpenFileName string filesystem.getOpenFileName(string defaultFilename) 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 (;).

Example:
filter = "All Files\0*.*\0Lua files\0*.lua\0Image files\0*.bmp;*.jpg\0\0"; local selectedFile = filesystem.getOpenFileName("", filter);
#filesystem.getSaveFileName string filesystem.getSaveFileName(string defaultFilename) string filesystem.getSaveFileName(string defaultFilename, string filter)

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

#filesystem.getCWD string filesystem.getCWD()

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

Example:
print("CWD:", filesystem.getCWD()); -- Prints out something like: -- CWD: C:/micromacro/scripts
#filesystem.setCWD filesystem.setCWD(string newCWD)

Modify the current working directory (CWD) to the given path.

You probably don't want to do this under normal conditions and it is not recommended unless you know what you're doing, otherwise unknown behavior could occur.

Page last updated at 2018-09-25 20:47:31


Copyright 2024