SlagDoc:File
From Plasmaworks
Contents |
Class File
| Properties |
|---|
| Methods |
|
| Base Types |
| Object, ReadableType, Readable<<Char>>, Writable<<Char>> |
| Implicit Singletons |
| FileManager, Global, ObjectManager, Math, BitwiseOperations, DegreesManager, RadiansManager, RandomNumberGenerator |
Overview
Represents a potential file in the operating system. A File object is created with a filepath; a file of that name may or may not exist yet.
A file object is both Readable and Writable as an input and output for characters. It may be used to obtain directory listings and manage files.
Class File uses the following terminology:
- filename
- The name of a file without any location information.
- path
- The directory location where the file is stored.
- filepath
- A filename with path information.
Examples:
# print every character in a file "test.txt"
forEach (ch in File("test.txt")) print( ch )
class RecursiveDirectoryListing
METHODS
method init:
# Recursively lists files starting in the current directory
list( "." )
method list( String filepath ):
local File file(filepath)
file.filepath = file.absolute_filepath
println( file.filepath )
if (file.is_directory)
forEach (entry in file.directory_listing)
list("$/$" (file.filepath,entry))
endForEach
endIf
endClass
Properties
| filepath : String |
|---|
|
The filepath of this file. |
Methods
| init( String filepath ) |
|---|
|
Initializes this file object with the given filepath. No operating system files are actually opened or created yet. |
| init( String _path, String _filename ) |
|---|
|
Joins together the given path with the given filename. |
| absolute_filepath().String |
|---|
|
Returns the absolute filepath (path + file) of this file. Note: if a filepath doesn't exist it will still be fleshed out with the current full path to allow this method to work with non-existent output files that you may wish to create. |
| absolute_path().String |
|---|
|
Returns the absolute path denoted by this File object. |
| change_dir() |
|---|
|
Sets the current working directory to the one specified by this file. |
| copy( String new_name ) |
|---|
|
Makes a copy of this file named new_name. |
| create_appender().TextWriter |
|---|
|
Like write() but appends data to the file, if it exists, rather than overwriting it. |
| create_reader().Reader<<Char>> |
|---|
|
Creates and returns a character reader for this file which opens the corresponding file in the operating system for reading. If the file doesn't exist or if there's some other error then a FileError exception is thrown. |
| create_writer().TextWriter |
|---|
|
Creates and returns a character writer for this file which opens the corresponding file in the operating system for writing. If an error occurs then a FileError exception is thrown. |
| delete() |
|---|
|
Attempts to delete this file or folder from disk. Throws a FileError if the operation fails. |
| directory_listing().String[] |
|---|
|
Returns a list of filenames and directory names contained within the directory represented by this File object. Throws a FileError if this file does not denote a valid directory. Note: the list of entries returned will not contain the current directory "." or the parent directory "..". See also: directory_listing(Int32) |
| directory_listing( Int32 flags ).String[] |
|---|
|
A directory listing with more control over the results. Send in the following File flags (e.g. File.relative):
|
| exists().Logical |
|---|
|
Returns whether or not this file already exists within the operating system. |
| extension().String |
|---|
|
Returns extension of the filename including the dot. Returns an empty string if the filename has no extension. Example: println( File("standard.slag").extension ) # prints: .slag
println( File("standard").extension ) # empty string
|
| filename().String |
|---|
|
Returns the filename (without path information) denoted by this File. If this file points to directory an empty string ("") will be returned. |
| is_directory().Logical |
|---|
|
Returns "true" if the path of this file specifies a directory. |
| mkdir() |
|---|
|
Creates a directory at this filepath. |
| newer_than( String other_filepath ).Logical |
|---|
|
Returns true if this file is newer than the file at the given other_filepath. |
| path().String |
|---|
|
Returns the path denoted by this File object. This may be relative or absolute depending on the string passed into the initializer. At a minimum, the relative path "." will be returned. |
| recursive_delete() |
|---|
|
Recursively deletes this File and everything in it if it's a directory. Throws a FileError if any part of the operation fails. |
| rename( String new_name ) |
|---|
|
Attempts to rename this file to have the given filename. This File object's name is not changed; you have to manually create a new File() if you want to access the renamed file. Throws a FileError if the operation fails. |
| save( Byte[] bytes ) |
|---|
|
Saves the given bytes to this file. |
| save( Char[] chars ) |
|---|
|
Saves the given characters to this file. |
| save( String st ) |
|---|
|
Saves the given String to this file. |
| size().Int32 |
|---|
|
Returns the byte size of this file. Throws a FileError if the file does not exist. |
| timestamp().Int64 |
|---|
|
Returns a timestamp that indicates when a file was last modified in milliseconds since Jan 1, 1970. Use Date(file.timestamp) to turn the timestamp into a date. Throws a FileError if the file isn't found. See also:
|
| to_String().String |
|---|
|
Returns the original filepath of this File object. |
| touch() |
|---|
|
Updates the timestamp on this file to the current time. Creates the file if it isn't there already. |
| type_name().String (inherited) |
|---|
|
Returns the true class name of this object. Implemented by the runtime; you should not override this method. Equivalent to calling "runtime_type.name" in the introspection library. Example: local Object obj = "Hello World" println( obj.type_name ) # prints: String See also: |
| with_back_slashes().File |
|---|
|
Returns a new File with any forward slashes in the fileptah (/) converted to forward slashes (\). |
| with_forward_slashes().File |
|---|
|
Returns a new File with any back slashes in the fileptah (\) converted to forward slashes (/). |
| with_os_slashes().File |
|---|
|
On Windows, returns a File whose filepath contains only backslashes ('\'). On Mac and Unix the filepath contains only forward slashes. |
The content on this SlagDoc page was automatically generated. Any changes maybe overwritten in the future - post corrections and updates to the Plasmacore forums or email Abe.Pralle at Plasmaworks.com.