Help Command: Contents of the directory_operations package
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"
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/"
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"
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"
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.