The fs
library provides essential file system functiuons for files and folders.
local fs = require("fs");
Returns the path to the current remote file.
path = fs.remotefile();
Returns the path to the current remote directory.
path = fs.remotedir();
Returns path to the working directory.
path = fs.workingdir();
Returns the path to the users home directory.
path = fs.homedir();
Returns the path to the server directory.
path = fs.appdir();
Returns the path for the special folder specified by csidl
(integer or string).
path = fs.special("startmenu");
path = fs.special("csidl_startmenu");
Refer to MSDN for a list of CSIDL values.
Returns the name (excluding extanstion) of the specified path
.
--name will be "log"
name = fs.name("c:\\temp\\log.txt");
Returns the full name (including extanstion) of the specified path
.
--fullname will be "log.txt"
fullname = fs.fullname("c:\\temp\\log.txt");
Returns the extension of the specified path
.
--ext will be "txt"
ext = fs.extension("c:\\temp\\log.txt");
Returns true if path
exists.
exists = fs.exists();
Copys file or folder from source
to destination
.
fs.copy("c:\\temp\\log.txt", "c:\\temp2\\log.txt");
Moves file or folder from source
to destination
.
fs.move("c:\\temp\\log.txt", "c:\\temp2\\log.txt");
Renames file or folder from source
to destination
.
fs.rename("c:\\temp\\log.txt", "c:\\temp\\log2.txt");
Deletes file or folder localted at path
set recursive
to true if all files and folders in at the path should be deleted. If folder contains files or sub-folders and recursive
set to false the folder will not be deleted
--deletes the file log.txt
fs.delete("c:\\temp\\log.txt");
--deletes all files and folders located in temp
fs.delete("c:\\temp\\", true);
Returns path of the parent directory located ath the specified path
.
parent = fs.parent("c:\\temp");
Expands a path
.
fs.expand("c:\\temp\\newfile.txt");
Converts a string str
to a valid path.
--returns "c:\\temp\\log.txt" on windows.
path = fs.path("c:\\temp/log.txt");
Combines path a
with path b
handles missing slash between paths.
--combined will be "c:\\temp\\log.txt"
combined = fs.fullname("c:\\temp", "log.txt");
Given a relative path rel
the absolut path is returned
--abs will be "c:\\temp\\log.txt" if remote is located at "c:\\temp"
abs = fs.absolute("log.txt");
Returns a unique path name for a temporary file in the system's scratch directory.
path = fs.temp();
Returns a array of all the avalible root directories.
roots = fs.roots();
fs.files( path, [hidden] )
Returns an array of file located at the specified path
.
files = fs.files("c:\\");
--Print out paths to all files in the directory
for i = 1, #files do
print(files[i]);
end
fs.dirs( path, [hidden] )
Returns an array of sub-directories located at the specified path
.
dirs = fs.dirs("c:\\");
--Print out paths to all sub-directories in the directory
for i = 1, #dirs do
print(dirs[i]);
end
fs.list( path, [hidden] )
Returns an array of sub-directories and files located at the specified path
.
items = fs.list("c:\\");
--Print out paths to all sub-directories and files in the directory
for i = 1, #items do
print(items[i]);
end
Create the directory path
.
--if c:\temp\ exists then "newdir" is created.
fs.createdir("c:\\temp\\newdir");
Create the directory path
and all requierd parents.
--if c:\temp\ exists then "newdir" and "anotherdir" is created.
fs.createdirs("c:\\temp\\newdir\\anotherdir");
Creates a file path
.
--a file "newfile.txt" is created.
fs.createdirs("c:\\temp\\newfile.txt");
Write to a file. path
the file to write to and content
the information to write to file.
fs.write("c:\\temp\\log.txt", "This is some content");
Writes a list of lines
to a file located at path
.
fs.write("c:\\temp\\log.txt", {"Line 1", "Line 2"});
Appends a string containing content
to a file located at path
fs.append("c:\\temp\\log.txt", "new content");
Appends a list of lines
to a file located at path
fs.appendlines("c:\\temp\\log.txt", {"line3", "line4"});
Read the entire content from file. path
the file to read from.
content = fs.read("c:\\temp\\log.txt");
Returns a list of lines in the file located at path
lines = fs.readlines("c:\\temp\\log.txt");
Check if a path
is a file or not. Returns true if path
is a file.
--returns true since "newfile.txt" is a file
res = fs.isfile("c:\\temp\\newfile.txt");
--returns false since "c:\\temp\\" is not a file
res = fs.isfile("c:\\temp\\");
Check if a path
is a directory or not. Returns true if path
is a directory.
--returns false since "newfile.txt" is not a directory
res = fs.isdir("c:\\temp\\newfile.txt");
--returns true since "c:\\temp\\" is a directory
res = fs.isdir("c:\\temp\\");
fs.ishidden( path )
Check if file or directory located at path
is hidden by the filesystem.
--returns true if file is hidden.
res = fs.ishidden("c:\\temp\\newfile.txt");
Returns the size of a file or directory located at path
.
size = fs.size("c:\\temp\\newfile.txt");
Returns the time when the file or directory located at path
was created.
time = fs.created("c:\\temp\\newfile.txt");
Returns the time when the file or directory located at path
was modified.
time = fs.modified("c:\\temp\\newfile.txt");