File Class Reference

The PermanentFile and TemporaryFile JavaScript classes. Used to represent an actual image file on disk. More...

Public Slots

FilesetPath (const String &path)
 Specify absolute path of this image file. Name of file can not be changed if there is an open stream. More...
 
String path () const
 Retrieve file path. More...
 
FilesetExtension (const String &ext)
 Change extension for file name. Extension won't change if there is an open stream. More...
 
String extension () const
 Retrieve file extension. More...
 
bool exists () const
 Verify if file exists on disk. More...
 
bool remove ()
 
Stream Manipulation
bool isOpen () const
 Check if file is opened. More...
 
bool isClose () const
 Check if file is closed. More...
 
bool open (int m=int(IO::WRITE_ONLY))
 Open file stream for read/write. More...
 
bool close ()
 Close file stream. More...
 
void write (const String &text)
 Write string in current stream. More...
 
void writeLine (const String &text)
 Write string line in current stream. More...
 
void writeFile (File file)
 Write entire content of parameter file in current stream. More...
 
String read ()
 Read entire content of stream. More...
 
String readLine ()
 Read single line of stream. More...
 
File management
bool move (File dest)
 
bool copy (File dest)
 

Public Member Functions

 File ()
 Create a new File. More...
 
 File (String path)
 Create a new File. More...
 

Detailed Description

The PermanentFile and TemporaryFile JavaScript classes. Used to represent an actual image file on disk.

Files can be instantiated in the scripting environment or retrieved in an InputPort object.

In a script, there are two possible constructor: the PermanentFile or TemporaryFile. The PermanentFile takes the name of a file as an argument. Example:

file = new PermanentFile( "C:\file.txt" );
file.open( IO.WRITE_ONLY ); // open with write only stream
file.writeLine( "Hello World!" ); // write line to file
file.close(); // close file

The TemporaryFile takes an extension as an argument, an returns a temporary file with that extension. The temporary file and its containing directory will be deleted on exit.Example:

file = new TemporaryFile( "txt" );
file.open( IO.WRITE_ONLY ); // open with write only stream
file.writeLine( "Hello World!" ); // write line to file
file.close(); // close file

Constructor & Destructor Documentation

◆ File() [1/2]

File::File ( )

Create a new File.

◆ File() [2/2]

File::File ( String  path)

Create a new File.

Parameters
pathPath to physic File

Member Function Documentation

◆ close

bool File::close ( )
slot

Close file stream.

Returns
Sucess/Failure of operation

◆ copy

bool File::copy ( File  dest)
slot

Copy current File to new File destination

Parameters
destDestination
Returns
Result of operation

◆ exists

bool File::exists ( ) const
slot

Verify if file exists on disk.

Returns
exists on disk

◆ extension

String File::extension ( ) const
slot

Retrieve file extension.

Returns
extension String

◆ isClose

bool File::isClose ( ) const
slot

Check if file is closed.

Returns
stream status

◆ isOpen

bool File::isOpen ( ) const
slot

Check if file is opened.

Returns
stream status

◆ move

bool File::move ( File  dest)
slot

Move current File to new File destination

Parameters
destDestination
Returns
Result of operation

◆ open

bool File::open ( int  m = int(IO::WRITE_ONLY))
slot

Open file stream for read/write.

Parameters
mIO stream descriptor
Returns
Success/Failure of operation

◆ path

String File::path ( ) const
slot

Retrieve file path.

Returns
full path String

◆ read

String File::read ( )
slot

Read entire content of stream.

Returns
String

◆ readLine

String File::readLine ( )
slot

Read single line of stream.

Returns
String

◆ remove

bool File::remove ( )
slot

Remove physical file manually. Cannot remove file if there is an open stream.

Returns
Result of operation

◆ setExtension

File& File::setExtension ( const String &  ext)
slot

Change extension for file name. Extension won't change if there is an open stream.

Parameters
extExtension String of image file
Returns
File reference

◆ setPath

File& File::setPath ( const String &  path)
slot

Specify absolute path of this image file. Name of file can not be changed if there is an open stream.

Parameters
pathAbsolute path String of image file
Returns
File reference

◆ write

void File::write ( const String &  text)
slot

Write string in current stream.

Parameters
textText to write

◆ writeFile

void File::writeFile ( File  file)
slot

Write entire content of parameter file in current stream.

Parameters
fileFile object

◆ writeLine

void File::writeLine ( const String &  text)
slot

Write string line in current stream.

Parameters
textText to write