the fair gds editor MacroClassFile

File Class Reference

This class enables reading and writing files to disk. More...

This feature is only part of LayoutEditors C++ Macros.

See also: List of Classes


Detailed Description

This class provides a interface for reading and writing on 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:

   1   file f;
   2 
   3   // add platform spezific path like "/home/username/filename" or "c:/my Files/filename.txt"
   4   string s="poly_on_23.txt";
   5   f.filename=s;
   6   bool b=false;
   7 
   8   //open for output
   9   f.open(b);
  10 
  11   s="data";
  12   
  13   // write string
  14   f.write(s);
  15 
  16   // close file
  17   f.close();

Beside a file access this class also give access to directory data as well as reading and setting paths.

See also: example macro

This class is only available for LayoutEditor C++ Macros. For the other scripting interfaces native alternatives will exist.

Member Function Documentation

string file::baseName()

Returns: the base name of the file without the path and suffix. (introduced with version 20130504)

void file::close()

The file is closed.

string file::currentPath()

The current working path is returned.

bool file::exists()

The filename had to be set prior to the property filename.

Returns: true if filename exists. Otherwise false.

void file::find(string path, string s)

Find a file matching to the search string s. If a match is found, filename is set. Otherwise filename is set to "".

void file::findDir(string path, string s)

Find a folder matching to the search string s. If a match is found, filename is set. Otherwise filename is set to "".

void file::findNext()

Find an other file match to a previous find or findDir. If a match is found, filename is set. Otherwise filename is set to "".

string file::filename

Name of the file to operate with.

string file::homePath()

The home path is returned.

bool file::link(string linkname)

linkname will be created as link to the set file name. Returns true if the link can be created. (introduced with version 20170428)

bool file::open(bool mode=true)

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.

string file::path()

Returns: the file's path. This doesn't include the file name. (introduced with version 20130504)

string file::read()

Returns: the hole file is returned as a string

intList file::readBinary()

Returns: the hole file is returned as a intList. It reads a binary file with an int for each byte.

   1   intList list;
   2   file f;
   3   f.filename="data.bin";
   4   bool b=true;
   5 //open for input
   6   f.open(b);
   7   list=f.readBinary();
   8 // close file
   9   f.close();

(introduced with version 20130101)

bool file::remove()

Removes the file specified by the filename given. Returns true if successful; otherwise returns false.

void file::setCurrentPath(string path)

The default working directory is set to path.

void file::setCodec(string codec)

Uses codec to encode input/output. Many codec are supported like "UTF-8", "UTF-16", "ISO-8859-13"

string file::suffix()

Returns: the suffix of the file (introduced with version 20130504)

string file::tempPath()

The temp path is returned.

void file::write(string s)

The file is overwriten with the string s.

void file::writeBinary(intList list)

The file is overwriten with the intList list. It writesa binary file with an byte for each int in the list.

   1   file f;
   2   f.filename="data.bin";
   3   bool b=false;
   4  //open for output
   5   f.open(b);
   6   intList list;
   7   list.append(1);
   8   list.append(32);
   9   list.append(67);
  10   f.writeBinary(list);
  11 // close file
  12   f.close();

(introduced with version 20130101)

See also


CategoryMacroClass CategoryMacroClassBasic


MacroClassFile (last edited 2017-04-24 15:01:22 by JurgenThies)