|
This part of the guide contains detailed descriptions of the
BUSH built-in packages.
4.15 Files Package
The files package provides general functions pretaining to files.
GCC Ada Equivalent: GNAT.OS_Lib, GNAT.IO_Aux
The routines include:
- Pathnames: basename, dirname, is_absolute_path
- Access rights: exists, is_executable, is_executable_file,
is_readable, is_readable_file, is_writable, is_writable_file
- File type: is_regular_file, is_directory
- Misc: is_waiting_file, last_modified, length
b := files.basename( p )
Return the filename for the path p.
Example: b := files.basename( "/tmp/myfile.txt" ); -- returns "myfile.txt"
Ada Equivalent: none (AdaScript extension)
Parameters:
p |
in |
string |
required |
the pathname of the file |
s |
return value |
string |
required |
the filename |
|
b := files.dirname( p )
Return the directory portion of the path p.
Example: s := files.dirname( "/tmp/myfile.txt" ); -- returns "/tmp"
Ada Equivalent: none (AdaScript extension)
Parameters:
p |
in |
string |
required |
the pathname of the file |
s |
return value |
string |
required |
the directory portion of the path (without a trailing directory separator) |
|
b := files.exists( p )
Return true if the file at path p exists. The function works on directories and other special files.
Example: b := files.exists( "/tmp/myfile.txt" );
Ada Equivalent: GNAT.IO_Aux.File_Exists
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file exists |
|
b := files.is_absolute_path( p )
Return true if the path p is an absolute path.
Example: b := files.is_absolute_path( "/tmp/myfile.txt" ); -- returns true
Ada Equivalent: GNAT.OS_Lib.Is_Absolute_Path
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the path is not a relative path |
|
b := files.is_directory( p )
Return true if the file at path p exists and is a directory.
Example: b := files.is_directory( "/tmp/myfile.txt" ); -- returns false
Ada Equivalent: GNAT.OS_Lib.Is_Directory
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file is a directory |
|
b := files.is_executable( p )
Return true if the file or special file at path p exists and is executable.
Example: b := files.is_executable( "home_directory" );
Ada Equivalent: none (AdaScript extension)
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file is executable |
|
b := files.is_executable_file( p )
Return true if the file at path p exists, is regular and is executable.
Example: b := files.is_executable_file( "myscript.bush" );
Ada Equivalent: none (AdaScript extension)
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file is not a special file and is executable |
|
b := files.is_readable( p )
Return true if the file or special file at path p exists and is readable.
Example: b := files.is_readable( "home_directory" );
Ada Equivalent: none (AdaScript extension)
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file is readable |
|
b := files.is_readable_file( p )
Return true if the file at path p exists, is regular and is readable.
Example: b := files.is_readable_file( "/tmp/myfile.txt" );
Ada Equivalent: none (AdaScript extension)
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file is not a special file and is readable |
|
b := files.is_regular_file( p )
Return true if the file at path p exists and is a regular file.
Example: b := files.is_regular_file( "/tmp/myfile.txt" ); -- returns true
Ada Equivalent: GNAT.IO_Aux.File_Exists (but GNAT doesn't check for regular)
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file is not a special file |
|
b := files.is_waiting_file( p )
Return true if the file at path p exists, is regular, is_readable and is
not empty.
Example: b := files.is_waiting_file( "/tmp/myfile.txt" );
Ada Equivalent: none (AdaScript extension)
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file has waiting data to process |
|
b := files.is_writable( p )
Return true if the file or special file at path p exists and is writable.
Example: b := files.is_writable( "home_directory" );
Ada Equivalent: GNAT.OS_Lib.Is_Writable_File
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file is writable |
|
b := files.is_writable_file( p )
Return true if the file at path p exists, is regular and is writable.
Example: b := files.is_writable_file( "/tmp/myfile.txt" );
Ada Equivalent: GNAT.OS_Lib.Is_Writable_File (but GNAT doesn't check for regular)
Parameters:
p |
in |
string |
required |
the pathname of the file |
b |
return value |
boolean |
required |
true if the file is not a special file and is writable |
|
b := files.last_modified( p )
Return the time a file was last changed.
Example: t := files.last_modified( "/tmp/myfile.txt" );
Ada Equivalent: none (AdaScript extension)
Parameters:
p |
in |
string |
required |
the pathname of the file |
t |
return value |
calendar.time |
required |
the time of the last change |
|
l := files.size( p )
Return the size of the file at path p in bytes. The function works on directories and other special files.
Example: b := files.size( "/tmp/myfile.txt" );
Ada Equivalent: GNAT.OS_Lib.File_Length (without opening file)
Parameters:
p |
in |
string |
required |
the pathname of the file |
l |
return value |
long_integer |
required |
the length of the file |
|
If a file doesn't exist or is not accessible, an error will occur.
Back to Top
|