-
Notifications
You must be signed in to change notification settings - Fork 8
FileIO Library API
Brom Bresenham edited this page Nov 9, 2023
·
14 revisions
Signature | Return Type | Description |
---|---|---|
create( filepath:String ) | File | |
operator+( left:File, right:File ) | File | |
operator+( left:File, right:String ) | File | |
operator+( left:String, right:File ) | File |
Name | Type | Description |
---|---|---|
filepath | String |
Signature | Return Type | Description |
---|---|---|
abs() | File | |
appending( suffix:String ) | File | "filename.png".appending("@2x") -> "filename@2x.png" "filename.png".appending(null) -> "filename.png" |
character_writer() | CharacterToUTF8ByteWriter | |
common_folder( other:File ) | File | |
contains_wildcards() | Logical | |
contains( pattern:FilePattern ) | Logical | Returns true if this folder contains a file with the given pattern. |
conventional_filepath() | String | |
copy_to( destination:File, &if_different, &if_newer, &dry_run, &verbose, &ignore_hidden ) | Int32? | Copies a file or the contents of a folder to a specified file or folder. Returns the count of files copied or null on an error. |
crc32() | Int32 | |
create_folder() | Logical | Creates the specified folder along with intermediate folders if necessary. Returns 'true' on success or if the filepath already exists as a folder. Returns 'false' on failure to |
delete() | Logical | |
description() | String | |
esc() | String | |
exists() | Logical | |
extension() | String | |
filename() | String | |
filepath_before_wildcards() | String | Example: alpha/beta/image*.png -> alpha/beta |
folder() | String | |
folder_before_wildcards() | String | Example: alpha/beta/image*.png -> alpha/beta |
has_parent() | Logical | |
is_absolute() | Logical | |
is_folder() | Logical | |
is_hidden() | Logical | |
is_valid_utf8() | Logical | |
is_newer_than( other:File ) | Logical | |
is_valid_filename_character( ch:Character, &any_os ) | Logical | |
listing( filepattern:FilePattern?, &ignore_hidden, &absolute, &omit_path, &files, &folders, &unsorted, &recursive ) | String[] | Use the filepattern '**' for a recursive listing. |
listing( pattern:String, &ignore_hidden, &absolute, &omit_path, &files, &folders, &unsorted, &recursive ) | String[] | |
load_as_bytes( &discard_bom ) | Byte[] |
discard_bom Discard the Byte Order Marker, if it exists. |
load_as_string( [encoding=StringEncoding.AUTODETECT:StringEncoding] ) | String | |
operator/( other:File ) | File | |
operator/( other_filepath:String ) | File | |
operator/( pattern:FilePattern ) | File | |
operator==( other:File ) | Logical | Returns true if 'this' and 'other' both exist, are the same size, and have the same CRC32. |
parent( [level=1:Int32] ) | File | |
print_writer( &append ) | PrintWriter | |
reader() | FileReader | |
relative_to( base_folder:File ) | File | |
rename( destination:File ) | Logical | |
resolved() | File | |
save( data:Byte[] ) | Logical | |
save( data:String, &bom ) | Logical | |
separator() | Character | |
size() | Int64 | |
split_filepath_and_extension() | (filepath:String,extension:String) | |
symlink( target:File ) | Symlinks this File to the target file. Unix-style example: File("/usr/local/bin/cmdlauncher").symlink(File("/opt/myapp/bin/cmd")) | |
timestamp_ms() | Int64 | Returns the last modified time. |
to<<Object>>() | Boxed<<File>> | |
to<<String>>() | String | |
with_destination( destination:File ) | File |
Uses console-style filename and folder rules to modify a source filepath given a destination filepath. File( "folder1/filename1" ).with_destination( File("folder2/filename2") ) -> "folder2/filename2" File( "folder1/filename1" ).with_destination( File("folder2") ) -> "folder2/filename1" File( "folder1/filename1" ).with_destination( File("filename2") ) -> "filename2" File( "filename1" ).with_destination( File("folder2/filename2") ) -> "folder2/filename2" File( "filename1" ).with_destination( File("folder2") ) -> "folder2/filename1" File( "filename1" ).with_destination( File("filename2") ) -> "filename2" File( "folder1" ).with_destination( File("folder2/filename2") ) -> "folder2/filename2" File( "folder1" ).with_destination( File("folder2") ) -> "folder2/folder1" File( "folder1" ).with_destination( File("filename2") ) -> "filename2" (folder1 renamed to filename2) Definitions - path: .exists and .is_folder - filename: not .exists or (.exists and not .is_folder) |
with_extension( ext:String ) | File |
if ext is null or "": Removes any current ".extension". else Removes any current ".extension" and adds ".$"(ext). |
without_extension() | File | |
without_trailing_separator() | File | Removes trailing slash on anything except "/" |
writer( &append ) | FileWriter |
extends Object
incorporates Reader<<$DataType>>
Signature | Return Type | Description |
---|---|---|
stderr() | FDReader | |
stdin() | FDReader |
Name | Type | Description |
---|---|---|
auto_close | Logical | |
buffer | Byte[] | |
buffer_position | Int32 | |
fd | Int32 | |
position | Int32 |
Signature | Return Type | Description |
---|---|---|
init( fd:Int32, [auto_close=true:Logical] ) | ||
buffer_more() | Logical | Used by Process which needs to keep buffering from both the stdout and stderr of a process to make sure the process doesn't get blocked. |
close() | ||
has_another() | Logical | |
is_open() | Logical | |
on_cleanup() | ||
on_end_use() | ||
on_use() | FDReader | |
peek() | Byte | |
position() | Int32 | |
read() | Byte | |
read( buffer:Byte[], limit:Int32 ) | Int32 | |
reset() | ||
seek( pos:Int32 ) | ||
skip( n:Int32 ) | ||
to<<Byte[]>>() | Byte[] | |
to<<String>>() | String |
extends Object
incorporates Writer<<$DataType>>
Signature | Return Type | Description |
---|---|---|
stdout() | FDWriter |
Name | Type | Description |
---|---|---|
auto_close | Logical | |
buffer | Byte[] | |
error | Logical | |
fd | Int32 | |
position | Int32 |
Signature | Return Type | Description |
---|---|---|
init( fd:Int32, [auto_close=true:Logical] ) | ||
close() | ||
flush() | ||
on_cleanup() | ||
on_use() | FDWriter | |
on_end_use( err:Exception ) | Exception | |
position() | Int32 | |
reset() | ||
seek_end() | ||
seek( pos:Int32 ) | ||
skip( n:Int32 ) | ||
write( bytes:Byte[] ) | ||
write( ch:Byte ) | ||
write( text:String ) |
extends Object
Name | Type | Description |
---|---|---|
callback | Function(String) | |
empty_segments | String[] | |
filepath_segments | String[] | |
filepaths | String[] | |
options | FileListingOption | |
path_segments | String[] | |
pattern | FilePattern | |
pattern_segments | String[] |
Signature | Return Type | Description |
---|---|---|
init( folder_or_filepath:File, _pattern:FilePattern?, options:FileListingOption ) | ||
collect( filename:String ) | ||
fix( pattern:String ) | String | Without this fix, "**Alpha*" would not match "Source/Alpha.rogue" |
Category | Value | Description |
---|---|---|
ABSOLUTE | 1 | |
FILES | 2 | |
FOLDERS | 4 | |
IGNORE_HIDDEN | 8 | |
OMIT_PATH | 16 | |
RECURSIVE | 32 | |
UNSORTED | 64 |
Name | Type | Description |
---|---|---|
categories | FileListingOption[] |
Signature | Return Type | Description |
---|---|---|
create( name:String ) | FileListingOption | |
create( value:Int32 ) | FileListingOption |
Name | Type | Description |
---|---|---|
value | Int32 |
Signature | Return Type | Description |
---|---|---|
description() | String | |
is_absolute() | Logical | |
is_files() | Logical | |
is_folders() | Logical | |
is_ignore_hidden() | Logical | |
is_omit_path() | Logical | |
is_recursive() | Logical | |
is_unsorted() | Logical | |
name() | String | |
operator!() | FileListingOption | |
operator?() | Logical | |
operator&( flag:FileListingOption ) | FileListingOption | |
operator==( other:FileListingOption ) | Logical | |
operator|( flag:FileListingOption ) | FileListingOption | |
set_is_absolute( setting:Logical ) | ||
set_is_files( setting:Logical ) | ||
set_is_folders( setting:Logical ) | ||
set_is_ignore_hidden( setting:Logical ) | ||
set_is_omit_path( setting:Logical ) | ||
set_is_recursive( setting:Logical ) | ||
set_is_unsorted( setting:Logical ) | ||
to<<Int32>>() | Int32 | |
to<<Object>>() | Object | |
to<<String>>() | String |
Signature | Return Type | Description |
---|---|---|
create( pattern:String ) | FilePattern |
Name | Type | Description |
---|---|---|
pattern | String |
Signature | Return Type | Description |
---|---|---|
description() | String | |
matches( filepath:String, &ignore_case ) | Logical |
Determines whether or not the given filepath matches the given semi-Unix/Dos-style 'wildcard pattern'. 'pattern' is a regular text string that may contain the following special characters: * - Matches any number of characters but does not match '/' ** - Matches any number of characters including slashes ***/ - Matches any number of characters and a slash or else nothing. ? - Matches any one character except '/' Note: A filepath with a ./ prefix is checked with and without the prefix. |
operator==( other:FilePattern ) | Logical | |
to<<Object>>() | Boxed<<FilePattern>> | |
to<<String>>() | String |
extends Object
incorporates Reader<<$DataType>>
Name | Type | Description |
---|---|---|
buffer | Byte[] | |
buffer_position | Int32 | |
count | Int32 | |
error | Logical | |
filepath | String | |
position | Int32 |
Signature | Return Type | Description |
---|---|---|
init() | ||
init( _filepath:String ) | ||
close() | ||
fp() | Int64 | |
has_another() | Logical | |
on_cleanup() | ||
on_end_use() | ||
on_use() | FileReader | |
on_end_use( this_reader:FileReader ) | ||
open( filepath:String ) | Logical | |
peek() | Byte | |
position() | Int32 | |
read() | Byte | |
read( result:Byte[], limit:Int32 ) | Int32 | |
remaining() | Int32 | |
reset() | ||
seek( pos:Int32 ) | ||
skip( n:Int32 ) | ||
to<<Byte[]>>() | Byte[] | |
to<<String>>() | String |
extends Object
Manages a set of filepath strings.
Name | Type | Description |
---|---|---|
base_folder | String | |
filepath_set | [String:String] |
Signature | Return Type | Description |
---|---|---|
init( base_folder:File, pattern:FilePattern, &ignore_hidden=true, &include_folders ) | ||
init( base_folder:File, pattern:String, &ignore_hidden=true, &include_folders ) | ||
init( base_folder:String, &allow_pattern=true, &include_folders ) | ||
init( base_folder:String, pattern:FilePattern, &ignore_hidden=true, &include_folders ) | ||
init( base_folder:String, pattern:String, &ignore_hidden=true, &include_folders ) | ||
add( pattern:FilePattern, &ignore_hidden=true, &include_folders ) | ||
add( pattern:String, &ignore_hidden=true, &include_folders ) | ||
any_newer_than( filepath:String ) | Logical | |
contains( file:File ) | Logical | |
contains( filepath:String ) | Logical | |
copy_to( to_folder:File, &if_newer, &if_different, &verbose, &dry_run ) | ||
count() | Int32 | |
delete( &verbose, &dry_run ) | ||
filepaths() | TableValuesIterator<<String,String>> | |
files() | File[] | |
get( index:Int32 ) | String | |
newest_timestamp_ms() | Int64? | |
oldest_timestamp() | Int64? | |
relative_filepaths() | String[] | |
relative_files() | File[] | |
relative_filepath( filepath:String ) | String | |
remove( files:Files ) | Removes files from this listing but not from the filesystem - use delete() for that. | |
remove( pattern:FilePattern ) | Removes files from this listing but not from the filesystem - use delete() for that. | |
remove( pattern:String ) | Removes files from this listing but not from the filesystem - use delete() for that. | |
remove( query:Function(String)->Logical ) | Removes files from this listing but not from the filesystem - use delete() for that. | |
sync_to( dest_folder:File, &verbose, &keep_unused, &dry_run, &missing_only, &if_newer ) | Int32 | If 'if_newer' is not specified then files are copied if they are different. |
to<<File[]>>() | File[] | |
to<<String>>() | String | |
to<<String[]>>() | String[] |
extends Object
incorporates Writer<<$DataType>>
Name | Type | Description |
---|---|---|
buffer | Byte[] | |
error | Logical | |
filepath | String | |
position | Int32 |
Signature | Return Type | Description |
---|---|---|
init() | ||
init( _filepath:String, append:Logical ) | ||
close() | ||
flush() | ||
fp() | Int64 | |
on_cleanup() | ||
on_use() | FileWriter | |
on_end_use( err:Exception ) | Exception | |
on_end_use( this_writer:FileWriter ) | ||
open( filepath:String, append:Logical ) | Logical | |
position() | Int32 | |
reset() | ||
seek_end() | ||
seek( pos:Int32 ) | ||
skip( n:Int32 ) | ||
write( bytes:Byte[] ) | ||
write( ch:Byte ) | ||
write( data:String ) |
extends Object
Useful when a re-entrant program needs a mutex - for example a CGI program that is invoked multiple times concurrently.
USAGE
uses FileIO/MutexFile
use MutexFile("Mutex")
... # do other stuff
endUse
Name | Type | Description |
---|---|---|
fd | Int32 | |
file | File |
Signature | Return Type | Description |
---|---|---|
init( file:File ) | ||
init( filepath:String ) | ||
on_use() | MutexFile | |
on_end_use( THISOBJ:MutexFile ) |