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

Directory_Operations Package

The directory_operations package provides general functions pretaining to directories.

GCC Ada Equivalent: GNAT.Directory_Operations

Types in the package include:

  • directory_operations.dir_name_str: the name of a directory. A subtype used in this package to represent string values that are directory names. A directory name is a prefix for files that appear with in the directory. This means that for UNIX systems, the string includes a final '/', and for DOS-like systems, it includes a final '\' character. It can also include drive letters if the operating system provides for this. The final '/' or '\' in a Dir_Name_Str is optional when passed as a procedure or function in parameter. On OpenVMS, only Unix style path names are supported, not VMS style, but the directory and file names are not case sensitive.
  • directory_operations.path_name: a pathname. All routines using Path_Name handle both styles (UNIX and DOS) of directory separators (either slash or back slash).
  • directory_operations.path_style: the format of a pathname - path_style.unix, path_style.dos, path_style.system_default
  • directory_operations.environment_style: the format for environment variable substitution - environment_style.unix, environment_style.dos, environment_style.both, environment_style.system_default
  • directory_operations.dir_type_id: the id number of a dir_type resource, allocated by directory_operations.open

s := directory_operations.base_name( p [, f] )

 

Return the full file name portion of the pathname p. If suffix f exists, it is removed.

Example

s := directory_operations.base_name( "/tmp/myfile.txt" ); -- returns "myfile.txt"

Parameters

Param Mode Type Default Description
p in string required the pathname
f in string empty string the suffix to remove
s return value string required the full file name portion of the pathname

Exceptions

-

See Also

directory_operations.dir_name

Compare With

Ada: GNAT.Directory_Operations.Base_Name
PHP: basename

directory_operations.change_dir( p )

 

Change the current working directory to path p.

Example

directory_operations.change_dir( "/tmp" ); -- moves to "/tmp"

Parameters

Param Mode Type Default Description
p in string required the pathname of the directory

Exceptions

An error occurs if the directory does not exist or is not accessible.

See Also

-

Compare With

Ada: GNAT.Directory_Operations.Change_Dir
PHP:chdir

directory_operations.close( d )

 

Closes a directory referenced by the dir_type id.

Example

directory_operations.close( dir );

Parameters

Param Mode Type Default Description
d in dir_type_id required the id of a directory file resource

Exceptions

An error occurs if the dir_type is not open.

See Also

directory_operations.open

Compare With

Ada: GNAT.Directory_Operations.Open

s := directory_operations.dir_name( p )

 

Return the directory portion of the pathname p. This is similar to the UNIX dirname command. Everything after the last directory separator is removed. If there is no directory separator the current working directory is returned. Note that the contents of path is case-sensitive on systems that have case-sensitive file names (like Unix), and non-case-sensitive on systems where the file system is also non-case-sensitive (such as Windows, and OpenVMS).

Example

s := directory_operations.dir_name( "/tmp/myfile.txt" ); -- returns "/tmp/"

Parameters

Param Mode Type Default Description
p in string required the pathname
s return value directory_operations. dir_name_str required the directory portion of the pathname

Exceptions

-

See Also

-

Compare With

Ada: GNAT.Directory_Operations.Dir_Name
PHP: dirname

c := directory_operations.dir_separator

 

Return the directory separator for the operating system.

Example

c := directory_operations.dir_separator; -- returns '/' on Linux

Parameters

Param Mode Type Default Description
c return value character required the directory separator character

Exceptions

-

See Also

-

Compare With

Ada: GNAT.Directory_Operations.Dir_Separator
PHP: DIRECTORY_SEPARATOR

s := directory_operations.expand_path( p [,t] )

 

Expand variables in a pathname, substituting environment variables. This will not substitute SparForte variables but rather variables that are available for import from the previous environment. Returns Path with environment variables (or logical names on OpenVMS) replaced by the current environment variable value. For example, $HOME/mydir will be replaced by /home/joe/mydir if $HOME environment variable is set to /home/joe and Mode is UNIX. If an environment variable does not exists the variable will be replaced by the empty string. Two dollar or percent signs are replaced by a single dollar/percent sign. Note that a variable must start with a letter.

Example

s := directory_operations.expand_path( "$HOME/tmp", environment_style.unix );

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
t in string environment_style.system_default the style of operating system substitutions
s return value directory_operations.path_name required the new pathname

Exceptions

-

See Also

-

Compare With

Ada: GNAT.Directory_Operations.Expand_Path

s := directory_operations.file_extension( p )

 

Return the file suffix portion of the pathname p. The suffix is the string after the last dot, including the dot itself. For example, if the file name is "file1.xyz.adq", then the returned value would be ".adq". If no dot is present in the file name, or the last character of the file name is a dot, then the null string is returned.

Example

s := directory_operations.file_extension( "/tmp/myfile.txt" ); -- returns ".txt"

Parameters

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

Exceptions

-

See Also

-

Compare With

Ada: GNAT.Directory_Operations.File_Extension
PHP: pathinfo

s := directory_operations.file_name( p )

 

Return the file name without an extension from the pathname p. This is equivalent to Base_Name with default extension value.

Example

s := directory_operations.dir_name( "/tmp/myfile.txt" ); -- returns "myfile"

Parameters

Param Mode Type Default Description
p in string required the pathname
s return value string required the file name without suffix

Exceptions

-

See Also

-

Compare With

Ada: GNAT.Directory_Operations.File_Name
PHP: pathinfo

s := directory_operations.format_pathname( p [,t] )

 

Convert a pathname to an operating system. If style t is not specified, it uses the default for the system. Removes all double directory separator and converts all '\' to '/' if t is UNIX and converts all '/' to '\' if t is set to DOS. This function will help to provide a consistent naming scheme running for different environments. If t is set to System_Default the routine will use the default directory separator on the running environment.

Example

s := directory_operations.format_pathname( "/tmp", path_style.dos ); -- returns "tmp"

Parameters

Param Mode Type Default Description
p in string required the pathname of the file
t in string path_style.system_default the operating system to convert to
s return value directory_operations. path_name required the new pathname

Exceptions

-

See Also

-

Compare With

Ada: GNAT.Directory_Operations.Format_Pathname
PHP: realpath

p := directory_operations.get_current_dir

 

Return the current (present) working directory.

Example

p := directory_operations.get_current_dir;

Parameters

Param Mode Type Default Description
p return value directory_operations. dir_name_str required the current working directory

Exceptions

See Also

directory_operations.change_dir

Compare With

Ada: GNAT.Directory_Operations.Get_Current_Dir
PHP: getcwd

directory_operations.make_dir( p )

 

Create a new directory specified by path p.

Example

directory_operations.make_dir( "/foo" ); -- makes "/foo"

Parameters

Param Mode Type Default Description
p in string required the pathname of the directory

Exceptions

An error occurs if the directory cannot be made.

See Also

directory_operations.remove_dir

Compare With

Ada: GNAT.Directory_Operations.Make_Dir
PHP: mkdir

b := directory_operations.is_open( d )

 

Return true if the directory is open.

Example

b := directory_operations.is_open( dir );

Parameters

Param Mode Type Default Description
b return value boolean required true if directory is open
d in dir_type_id required the id of a directory file resource

See Also

-

Compare With

Ada: GNAT.Directory_Operations.Is_Open

directory_operations.open( d, p )

 

Opens the directory named p and returns a dir_type id and is positioned at the first entry in the directory.

Example

directory_operations.open( dir, "/tmp" );

Parameters

Param Mode Type Default Description
d out dir_type_id required the id of a directory file resource
p in string required the pathname of the directory

Exceptions

An error occurs if the directory does not exist or is not accessible.

Implementation Note

SparForte strings are not arrays so the length of the string is not returned as it is in Ada.

See Also

directory_operations.close

Compare With

Ada: GNAT.Directory_Operations.Open

directory_operations.read( d, s )

 

Reads the next entry from the directory and returns the name as s. This list includes the "." and ".." directory entries. If s is empty, then the end of the directory is reached.

Example

directory_operations.read( dir, filename );

Parameters

Param Mode Type Default Description
d in dir_type_id required the id of a directory file resource
s out string required a directory entry

Exceptions

An error occurs if the directory does not exist or is not accessible.

Implementation Note

The directory entry is limited to 1024 characters.

See Also

-

Compare With

Ada: GNAT.Directory_Operations.Read

directory_operations.remove_dir( p [, r] )

 

Delete directory specified by path p. Delete recursively if r is true.

Example

directory_operations.remove_dir( "/tmp/empty" );

Parameters

Param Mode Type Default Description
p in string required the pathname of the directory
r in boolean false true to remove recursively

Exceptions

An error occurs if the directory does not exist or is not accessible.

See Also

directory_operations.make_dir

Compare With

Ada: GNAT.Directory_Operations.Remove_Dir
PHP: rmdir

 
[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]