[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

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_accessed, last_changed, last_modified, size

b := files.basename( p )

 

Return the filename for the path p.

Example

b := files.basename( "/tmp/myfile.txt" ); -- returns "myfile.txt"

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
s return value string required the filename

Exceptions

-

See Also

directory_operations.base_name

Compare With

Ada: Gnat.Directory_Operations.Base_Name
PHP: basename

b := files.dirname( p )

 

Return the directory portion of the path p.

Example

s := files.dirname( "/tmp/myfile.txt" ); -- returns "/tmp"

Parameters

Param Mode Type Default Description
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)

Exceptions

-

See Also

directory_operations.dir_name

Compare With

Ada: Gnat.Directory_Operations.Dir_Name
PHP: dirname

b := files.exists( p )

 

Return true if the file at path p exists. The function works on directories and other special files. It does not follow symbolic links.

Example

b := files.exists( "/tmp/myfile.txt" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
b return value boolean required true if the file exists

Exceptions

-

See Also

-

Compare With

Ada: GNAT.IO_Aux.File_Exists
PHP: 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

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
b return value boolean required true if the path is not a relative path

Exceptions

-

See Also

-

Compare With

Ada: GNAT.OS_Lib.Is_Absolute_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

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
b return value boolean required true if the file is a directory

Exceptions

-

See Also

-

Compare With

Ada: GNAT.OS_Lib.Is_Directory
PHP: is_dir

b := files.is_executable( p )

 

Return true if the regular file, directory or special file at path p exists and is executable.

Example

b := files.is_executable( "home_directory" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
b return value boolean required true if the file is executable

Exceptions

-

See Also

files.is_executable_file

Compare With

PHP: 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.sp" );

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

files.is_executable_file

Compare With

-

b := files.is_readable( p )

 

Return true if the regular file, directory or special file at path p exists and is readable.

Example

b := files.is_readable( "home_directory" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
b return value boolean required true if the file is readable

Exceptions

-

See Also

files.is_readable_file

Compare With

PHP: 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" );

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

files.is_readable

Compare With

-

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

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
b return value boolean required true if the file is not a special file

Exceptions

-

See Also

files.exists

Compare With

PHP: is_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" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
b return value boolean required true if the file has waiting data to process

Exceptions

-

See Also

files.is_readable_file
files.size

Compare With

-

b := files.is_writable( p )

 

Return true if the regular file, directory or special file at path p exists and is writable.

Example

b := files.is_writable( "home_directory" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
b return value boolean required true if the file is writable

Exceptions

-

See Also

files.is_writable_file

Compare With

Ada: GNAT.OS_Lib.Is_Writable_File

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" );

Parameters

Param Mode Type Default Description
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

Exceptions

-

See Also

files.is_writable

Compare With

-

t := files.last_accessed( p )

 

Return the time the file specified by p was last accessed.

Example

t := files.last_accessed( "/tmp/myfile.txt" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
t return value calendar.time required the time of the last access

Exceptions

-

See Also

-

Compare With

PHP: fileatime

t := files.last_changed( p )

 

Return the time the inode of the file specified by p was last changed (often, but not always, the time the file was created).

Example

t := files.last_charged( "/tmp/myfile.txt" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
t return value calendar.time required the time of the last change

Exceptions

-

See Also

-

Compare With

PHP: filectime

t := files.last_modified( p )

 

Return the time the file specified by p was last modified.

Example

t := files.last_modified( "/tmp/myfile.txt" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
t return value calendar.time required the time of the last modification

Exceptions

-

See Also

-

Compare With

PHP: filemtime

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" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
l return value long_integer required the length of the file

Exceptions

If a file doesn't exist or is not accessible, an error will occur.

See Also

-

Compare With

Ada: GNAT.OS_Lib.File_Length (without opening file)
PHP: filesize

Rationale

I don't remember why I named this function "size". "size" is the standard terminology, and it may be that I wasn't aware of File_Length when I created this subprogram.

 
[Right Submenu]

 Summary

 arrays

 btree_io

 calendar

 cgi

 chains

 command_line

 db/ postgresql

 dbm

 directory_operations

 doubly_linked...

 dynamic_hash_...

 enums

 exceptions

 files

 gnat.cgi

 gnat.crc32

 hash_io

 lock_files

 memcache

 memcache.highread

 mysql

 mysqlm

 numerics

 os

 pen

 pen (OpenGL)

 records

 sound

 source_info

 stats

 strings

 System

 teams

 templates

 text_io

 units

[Back to Top] Back To Top [Small Forte Symbol]