[BUSH User Guide]
 
Home Page Introduction Tutorials Reference Packages Hacking
 
  Packages  
4.1 Using Packages
4.2 text_io (Console I/O)
4.3 text_io (File I/O)
4.4 sound
4.5 source_info
4.6 System
4.7 numerics
4.8 strings
4.9 command_line
4.10 lock_files
4.11 cgi
4.12 calendar
4.13 units
4.14 arrays
4.15 files
4.16 db (Database)
4.17 stats
4.18 pen
4.19 mysql
4.20 os
4.21 directory_operations
 
This part of the guide contains detailed descriptions of the BUSH built-in packages.
 

4.21 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


c := directory_operations.dir_separator

Return the directory separator for the operating system.
Example: c := directory_operations.dir_separator; -- returns '/' on Linux
Ada Equivalent: GNAT.Directory_Operations.Dir_Separator
Parameters: none
c return value character required the directory separator character


directory_operations.change_dir( p )

Change the current directory.
Example: directory_operations.change_dir( "/tmp" ); -- moves to "/tmp"
Ada Equivalent: GNAT.Directory_Operations.Change_Dir
Parameters:
p in string required the pathname of the directory

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


directory_operations.make_dir( p )

Create a new directory p.
Example: directory_operations.make_dir( "/tmp" ); -- makes "/tmp"
Ada Equivalent: GNAT.Directory_Operations.Make_Dir
Parameters:
p in string required the pathname of the directory

An error occurs if the directory cannot be made.


directory_operations.remove_dir( p [, r] )

Delete directory p. Delete recursively if r is true.
Example: directory_operations.remove_dir( "/tmp/empty" );
Ada Equivalent: GNAT.Directory_Operations.Remove_Dir
Parameters:
p in string required the pathname of the directory
r in boolean false true to remove recursively

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


p := directory_operations.get_current_dir

Return the current (present) working directory.
Example: p := directory_operations.get_current_dir;
Ada Equivalent: GNAT.Directory_Operations.Get_Current_Dir
Parameters:
p return value directory_operations.dir_name_str required the current working directory


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/"
Ada Equivalent: GNAT.Directory_Operations.Dir_Name
Parameters:
p in string required the pathname
s return value directory_operations.dir_name_str required the directory portion of the pathname


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"
Ada Equivalent: GNAT.Directory_Operations.Base_Name
Parameters:
p in string required the pathname
f in string "" the suffix to remove
s return value string required the full file name portion of the pathname


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"
Ada Equivalent: GNAT.Directory_Operations.File_Extension
Parameters:
p in string required the pathname
s return value string required the file suffix portion of the pathname


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"
Ada Equivalent: GNAT.Directory_Operations.File_Name
Parameters:
p in string required the pathname
s return value string required the file name without suffix


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"
Ada Equivalent: GNAT.Directory_Operations.Format_Pathname
Parameters:
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


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

Expand variables in a pathname, substituting environment variables. This will not substitute BUSH 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 );
Ada Equivalent: GNAT.Directory_Operations.Expand_Path
Parameters:
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

 Back to Top