This class enables reading and writing files to disk. More...
string | baseName() |
string | canonicalPath() |
void | close() |
string | currentPath() |
bool | exists() |
void | find(string path, string s) |
void | findDir(string path, string s) |
void | findNext() |
string | filename |
string | homePath() |
bool | isDir(string base) |
bool | link(string linkname) |
bool | mkDir(string baseDir, string name) |
bool | open(bool mode=true) |
string | path() |
string | projectPath() |
string | read() |
intList | readBinary() |
bool | remove() |
bool | rename(string newName) |
bool | rmDir(string baseDir, string name) |
void | setCurrentPath(string path) |
void | setCodec(string codec) |
string | suffix() |
string | tempPath() |
void | write(string s) |
void | writeBinary(intList list) |
This class provides a interface for reading and writing files. Also a access to directories is provided.
Typical step to read/write files are: create a file class, set the filename, open the file, read or write the data and close the file.
Example:
file f;
// add platform spezific path like "/home/username/filename" or "c:/my Files/filename.txt"
string s="poly_on_23.txt";
f.filename=s;
bool b=false;
//open for output
f.open(b);
s="data";
// write string
f.write(s);
// close file
f.close();
Beside a file access this class also give access to directory data as well as reading and setting paths.
This class is only available for LayoutEditor C++ Macros. For the other scripting interfaces native alternatives will exist.
Returns: the base name of the file without the path and suffix.
Returns: the canonical path of the file without any '.' and '..'. (introduced with releae 20210102)
The file is closed.
The current working path is returned.
The filename had to be set prior to the property filename.
Returns: true if filename exists. Otherwise false is returned.
file f;
f.filename="myfile.txt";
if (f.exists()) {
// do something
}
Find a file matching to the search string s. If a match is found, filename is set. Otherwise filename is set to an empty string.
Find a folder matching to the search string s. If a match is found, filename is set. Otherwise filename is set to an empty string.
Find an other file match to a previous find or findDir. If a match is found, filename is set. Otherwise filename is set to an empty string.
Name of the file to operate with.
The home path is returned.
Returns: true, if base in an existing directory; otherwise false is returned. (introduced with release 20180610)
linkname will be created as link to the set file name. Returns true if the link can be created.
Creates the folder name inside the folder baseDir. Returns true, if successful; otherwise returns false. (introduced with release 20180610)
Open a file. The filename had to be set prior to the property filename. If mode is true, the file is opened in readonly mode. If mode is false, the file is open as writeonly mode.
Returns: true if operation was successful. Otherwise false is returned.
Returns: the file's path. This doesn't include the file name.
Returns: the path where the LayoutEditor was started from. In most applications this is the project folder. (introduced with release 20201229)
Returns: the hole file is returned as a string
Returns: the hole file is returned as a intList. It reads a binary file with an int for each byte.
intList list;
file f;
f.filename="data.bin";
bool b=true;
//open for input
f.open(b);
list=f.readBinary();
// close file
f.close();
Removes the file specified by filename. Returns true, if successful; otherwise returns false.
Renames the file specified by filename to newName. Returns true, if successful; otherwise returns false. (introduced with release 20180610)
Removes the folder name inside the folder baseDir. Returns true, if successful; otherwise returns false. (introduced with release 20180610)
The default working directory is set to path.
Uses codec to encode input/output. Many codec are supported like "UTF-8", "UTF-16", "ISO-8859-13"
Returns: the suffix of the file
The temp path of the system is returned.
The file is overwriten with the string s.
The file is overwriten with the intList list. It writesa binary file with an byte for each int in the list.
file f;
f.filename="data.bin";
bool b=false;
//open for output
f.open(b);
intList list;
list.append(1);
list.append(32);
list.append(67);
f.writeBinary(list);
// close file
f.close();