mn8 Language Reference | Index    

File

SUMMARY: ATTRIBUTES SUMMARY  ELEMENTS SUMMARY  CONSTRUCTORS SUMMARY  NO OPERATORS  METHODS SUMMARYDETAIL: ATTRIBUTE DETAILS  ELEMENT DETAILS  CONSTRUCTOR DETAILS  NO OPERATORS  METHOD DETAILS

Description

The File concept is an abstraction of the regular operating system dependent file or directory. It is returned by the File, FTP protocol handlers and also if the content type is unknown by the HTTP protocol handler.

Usage

The URI of this file. Full path+file name.

            $myFile = File.create("file:///home/jon/xfile.txt")
            PRINT $myFile@url
                file:///home/jon/xfile.txt
The size of this file.
            PRINT $myFile.length
                1024

Returns the MIME type of the file. If the type is unknown to the system the "application/octet-stream" is returned.

            $myFile = File.create("file:///home/guest/diary.txt")
            PRINT $myFile@contentType
                text/plain

Version: 0.1
Authors:Remus Pereni (http://neuro.nolimits.ro)
Location:
Inherits: Concept

Attribute List

 @contentType TYPEOF String LABEL "contentType"
 @length TYPEOF Integer LABEL "length"
 @url TYPEOF String LABEL "url"
top

Element List

 content TYPEOF String LABEL "content"
top

Constructor List

create (String $pathname)
top

Method List

LogicalcanRead
LogicalcanWrite
Logicaldelete
Logicalexists
ConceptgetContent
static StringgetSeparator
SeriesgetLinks
LogicalisFile
LogicalisHidden
static Logicalmkdir (String $pathname)
Logicalrename (String $url)
LogicalsetContent (Concept $newValue)
LogicalsetReadOnly
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Attribute Info

@contentType

Label:contentType
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

Returns the MIME type of the file. If the type is unknown to the system the "application/octet-stream" is returned.

top

@length

Label:length
Type:Integer
Is Static:false
Is Hidden:false
Show Empty:true

The size of this file.

top

@url

Label:url
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

The URI of this file. Full path+file name.

top

Detailed Element Info

content

Label:content
Type:String
Is Static:false
Is Hidden:false
Is Multi:false
Show Empty:true

Returns the content of the file as non escaped (`line1\nline2`) String.

top

Detailed Constructor Info

create (String $pathname)
Parameters:
$pathname :A pathname string.

Creates a new File concept from the pathname given as parameter.

top

Detailed Method Info

canRead
Returns: Logical

Returns true if the file denoted by the URL exists and can be read, false otherwise.

            $file = File.create("file:///home/guest/notes.txt")
            print $file.canRead
            -- the result is --
            true
            

top
canWrite
Returns: Logical

Returns true if the file denoted by the URL exists and the application can write in it, false otherwise.

            $file = File.create("file:///home/guest/notes.txt")
            print $file.canWrite
            -- the result is --
            true
            

top
delete
Returns: Logical

Deletes the file or directory denoted by this abstract pathname. If it is a directory then it must be empty in order to succeed.

            $file = File.create("file:///home/guest/notes.txt")
            print $file.exists
            $file.delete
            print $file.exists
            -- the result is --
            true
            false
            

top
exists
Returns: Logical

Returns true if the file denoted by the URL exists and, false otherwise.

            $file = File.create("file:///home/guest/notes.txt")
            print $file.exists
            -- the result is --
            true
            

top
getContent
Returns: Concept
Exceptions:
fileOperationException :
(Error)
If unable to read a file.

Returns a Series with the content of the file denoted by the abstract path name. The content is wrapped in the Series respecting the Content Model.

            $file = File.create("file:///home/guest/test.txt")
            print $file.getContent
            -- the result is --
            This is a test.
            

top
static getSeparator
Returns: String

The system-dependent default name-separator character. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Win32 systems it is '\'.

            print File.getSeparator
            -- the result is --
            /
            

top
getLinks
Returns: Series

If the file denoted by the URL is a directory then returns all the URL's of the files and directories it contains as a Series. If it is a file then returns Nil.

            $file = File.create("file:///home/guest/")
            print $file.getLinks
            -- the result is --
            file:/home/guest/tmp/
            file:/home/guest/test.txt
            

top
isFile
Returns: Logical

Returns true if the file denoted by the URL exists and is a file, false otherwise.

            $file = File.create("file:///home/guest/")
            print $file.isFile
            -- the result is --
            false
            

top
isHidden
Returns: Logical

Returns true if the file denoted by the URL exists and is hidden, false otherwise.

            $file = File.create("file:///home/guest/test.txt")
            print $file.isHidden
            -- the result is --
            false
            

top
static mkdir (String $pathname)
Parameters:
$pathname :A pathname string.
Returns: Logical

Creates any directory marked by the abstract path name, including any necessary, but not existent parent directory.

            File.mkdir("file:///home/guest/docs/")
            $file = File.create("file:///home/guest/")
            print $file.getLinks
            -- the result is --
            file:/home/borzy/docs/
            file:/home/guest/tmp/
            file:/home/guest/test.txt
            

top
rename (String $url)
Parameters:
$url :URL with the new file name.
Returns: Logical

Returns true if the file can be renamed to the given name, false otherwise.

            $dir = File.create("file:///home/guest/")
            print $dir.getLinks
            $file = File.create("file:///home/guest/test.txt")
            $file.rename("/home/guest/text.log")
            print $dir.getLinks
            -- the result is --
            file:/home/guest/tmp/
            file:/home/guest/test.txt

            file:/home/guest/tmp/
            file:/home/guest/text.log
            

top
setContent (Concept $newValue)
Parameters:
$newValue : Value to be set. The $value must be a String or a ByteArray concept.
Returns: Logical
Exceptions:
fileOperationException :
(Error)
If unable to write a file.

Sets this File content to the specified value.

            $file = File.create("file:///home/guest/test.txt")
            print $file.getContent
            $file.setContent("This is the new content.")
            print $file.getContent
            -- the result is --
            This is a test.

            This is the new content.
            

top
setReadOnly
Returns: Logical

Sets the file's attribute to the value of the logical parameter true or false.

            $file = File.create("file:///home/guest/test.txt")
            print $file.setReadOnly
            -- the result is --
            true
            

top