Difference between revisions of "ObjectType:file"

From Lavish Software Wiki
Jump to navigation Jump to search
 
Line 28: Line 28:
  
 
== Examples ==
 
== Examples ==
 
+
;Example code
 +
function main()
 +
{
 +
    Declare Buffer buffer
 +
    Declare File file test.dat
 +
   
 +
    echo Filename=${File.Path}${File.Filename}
 +
    echo Opened=${File:Open(exists)}
 +
    echo Write=${File:Write["Line One...\n"](exists)}
 +
    echo Position=${File.Position}
 +
    echo Write=${File:Write["Line Two!\n"](exists)}
 +
    echo Position=${File.Position}
 +
    echo Truncate=${File:Truncate(exists)}
 +
    echo Size=${File.Size}
 +
    File:Close
 +
    echo Closed
 +
 
 +
    echo Filename=${File.Path}${File.Filename}
 +
    echo Opened Readonly=${File:Open[readonly](exists)}
 +
    echo Write=${File:Write["Overwriting Line One?\n"](exists)}
 +
    echo Position=${File.Position}
 +
    echo Read=${File.Read}
 +
    echo Position=${File.Position}
 +
    echo Read=${File.Read}
 +
    echo Position=${File.Position}
 +
    File:Close
 +
    echo Closed
 +
 
 +
    echo Filename=${File.Path}${File.Filename}
 +
    echo Opened Readonly=${File:Open[readonly](exists)}
 +
    echo ReadBinary=${File.ReadBinary[Buffer,${File.Size}]}
 +
    echo Null terminating...
 +
    Buffer.Byte[${File.Size}]:Set[0]
 +
    echo String=${Buffer.String[0]}
 +
    File:Close
 +
    echo Closed
 +
 
 +
    echo Filename=${File.Path}${File.Filename}
 +
    echo Opened=${File:Open(exists)}
 +
    Buffer.Int[0]:Set[12345678]
 +
    echo WriteBinary=${File:WriteBinary[Buffer,${File.Size}](exists)}
 +
    File:Close
 +
    echo Closed
 +
}
 
== See Also ==
 
== See Also ==
 
* [[LavishScript:Data Types|Data Types]]
 
* [[LavishScript:Data Types|Data Types]]

Revision as of 17:43, 29 August 2005

Description

Members

  • bool Open: TRUE if the file is open
  • filepath Path: Full path to this file
  • string Filename: Filename of this file
  • string Read: Reads a line from this file, up to 1024 characters long (result includes carriage return)
  • string Read[#]: Reads a line from this file, up to # characters long (result includes carriage return)
  • int ReadBinary[buffer variable,#]: Reads # bytes into the specified buffer. Result is the number of bytes read.
  • int Position: Current position within the file
  • int Size: Size of the file
  • bool EOF: TRUE if the previous Read or ReadBinary hit the end of the file

Methods

  • SetFilename[filename]: Sets the full path and filename. Only valid while file is closed.
  • Open: Opens the file
  • Open[readonly]: Opens the file in read-only mode
  • Close: Closes the file
  • Write[text]: Writes the given text to the file
  • WriteBinary[buffer variable,#]: Writes # bytes from the given buffer variable to the file
  • Seek[#]: Seeks to the specified position within the file
  • SeekEnd: Seeks to the end of the file
  • Skip[#]: Skips # bytes within the file
  • Truncate: Truncates the file at the current position (all data after this point in the file is removed)

Returns

The full path and filename to this file

Examples

Example code
function main() 
{ 
   Declare Buffer buffer 
   Declare File file test.dat 
    
   echo Filename=${File.Path}${File.Filename} 
   echo Opened=${File:Open(exists)} 
   echo Write=${File:Write["Line One...\n"](exists)} 
   echo Position=${File.Position} 
   echo Write=${File:Write["Line Two!\n"](exists)} 
   echo Position=${File.Position} 
   echo Truncate=${File:Truncate(exists)} 
   echo Size=${File.Size} 
   File:Close 
   echo Closed 
 
   echo Filename=${File.Path}${File.Filename} 
   echo Opened Readonly=${File:Open[readonly](exists)} 
   echo Write=${File:Write["Overwriting Line One?\n"](exists)} 
   echo Position=${File.Position} 
   echo Read=${File.Read} 
   echo Position=${File.Position} 
   echo Read=${File.Read} 
   echo Position=${File.Position} 
   File:Close 
   echo Closed 
 
   echo Filename=${File.Path}${File.Filename} 
   echo Opened Readonly=${File:Open[readonly](exists)} 
   echo ReadBinary=${File.ReadBinary[Buffer,${File.Size}]} 
   echo Null terminating... 
   Buffer.Byte[${File.Size}]:Set[0] 
   echo String=${Buffer.String[0]} 
   File:Close 
   echo Closed 
 
   echo Filename=${File.Path}${File.Filename} 
   echo Opened=${File:Open(exists)} 
   Buffer.Int[0]:Set[12345678] 
   echo WriteBinary=${File:WriteBinary[Buffer,${File.Size}](exists)} 
   File:Close 
   echo Closed 
} 

See Also