$file

( documentation for Telosys generator version 4.0.0 )


This object allows to work with a file located on the filesystem
Each file instance is created with $fn.file(..) or $fn.fileFromXxx(..)
It can be any type of filesystem item (file or directory)


Example :
   ## Get file instance :
   #set( $file = $fn.file('dir/foo.txt') )
   #set( $file = $fn.fileFromBundle("foo.txt") )
   #set( $file = $fn.fileFromModel('myfile.csv') )
   
   ## Use file instance :
   #if( $file.exists() && $file.isFile() )
   #set($content = $file.loadContent() )
   #end
   
   #foreach ( $line in $file.loadLines() )
    > $line
   #end

Since : 3.3.0

Attributes and methods
.absolutePath : String

Returns the absolute pathname string.

Example :
   $file.absolutePath

Since : 3.3.0

.canonicalPath : String

Returns the canonical pathname string.
A canonical pathname is both absolute and unique.
The precise definition of canonical form is system-dependent

Example :
   $file.canonicalPath

Since : 3.3.0

.exists() : boolean

Tests whether the file (or directory) exists

Example :
   #if( $file.exists() )
   ...
   #end

Since : 3.3.0

.isDirectory() : boolean

Tests whether the file is a directory

Example :
   #if( $file.isDirectory() )
   ...
   #end

Since : 3.3.0

.isFile() : boolean

Tests whether the file is a 'normal file'

Example :
   #if( $file.isFile() )
   ...
   #end

Since : 3.3.0

.isHidden() : boolean

Tests whether the file is a 'hidden file'
The exact definition of 'hidden' is system-dependent

Example :
   #if( $file.isHidden() )
   ...
   #end

Since : 3.3.0

.length : long

Returns the length of the file
The return value is 0 if the file is not a 'normal file' (eg directory)

Example :
   #if( $file.length > 0 )
   ...
   #end

Since : 3.3.0

.loadContent() : String

Loads all the lines of the file
Returns a single string containing all the lines

Example :
   $file.loadContent()
   #set($content = $file.loadContent() )
   

Since : 3.3.0

.loadContent(int n) : String

Same as loadContent() but ignore the first N lines

Parameters :
   n : number of lines to ignore (at the beginning of the file)

Example :
   $file.loadContent(1)
   #set($content = $file.loadContent(3) )
   

Since : 3.3.0

.loadLines() : List

Loads all the lines of the file
Returns a list of strings

Example :
   #foreach ( $line in $file.loadLines() )
    > $line
   #end

Since : 3.3.0

.loadLines(int n) : List

Same as loadLines() but ignore the first N lines

Parameters :
   n : number of lines to ignore (at the beginning of the file)

Example :
   #foreach ( $line in $file.loadLines(2) )
    > $line
   #end

Since : 3.3.0

.loadValues(String separator) : List>

Loads values (split lines) from the file
Values are the result after splitting each line according a given separator
Returns a list of values for each line (list of lists)

Parameters :
   separator : character to use as separator

Example :
   #set( $csv = $file.loadValues(";") )
   #foreach ( $line in $csv )
    > #foreach ( $v in $line ) [$v] #end
   
   #end
   

Since : 3.3.0

.loadValues(String separator, int n) : List>

Same as loadValues(separator) but ignore the first N lines

Parameters :
   separator : character to use as separator
   n : number of lines to ignore (at the beginning of the file)

Example :
   $file.loadValues(";", 2) )
   

Since : 3.3.0

.name : String

Returns the name of the file or directory.
This is just the last name in the absolute pathname.

Example :
   $file.name

Since : 3.3.0

.parent : String

Returns the pathname string for the file's parent
(or a void string if none)

Example :
   $file.parent

Since : 3.3.0

.path : String

Returns the path for the file or directory.

Example :
   $file.path

Since : 3.3.0