expanded class BASIC_DIRECTORY

All features

Very low-level basic tools for file-system directory handling and file path manipulation. This class is intended to be platform independant as much as possible. In order to remove from the client side the burden of file path computation, this class tries to compute automatically the system file notation using argument(s) of some of the very first call(s). As soon as the system notation has been properly detected, the result is internally memorized for all objects of type BASIC_DIRECTORY in a common private buffer. Besides the low-level nature of operations one can found in this class, all file path manipulations are done in a smart way (except when the system file path notation has not been detected automatically, which is quite uncommon). As an example, even if the directory separator is internally detected, this information is _intentionaly_ kept private to avoid low-level manipulation from the client side. Finally, this class is expanded in order to avoid as much as possible memory allocations.

Also consider high level facade class DIRECTORY if you don't want to deal directly with low level directory streams.

Direct parents

non-conformant parents

ANY

Summary

exported features

State of Current basic directory stream:

Connect and disconnect:

Scanning:

File path handling tools:

Disk modification:

Miscellaneous:

Details

directory_stream: POINTER

This pointer memorize the current directory stream being scanned (used to compute is_connected).

current_entry: POINTER

When is_connected, memorize the current entry in the current directory_stream.

is_connected: BOOLEAN

Is Current connected to some directory stream ?

end_of_input: BOOLEAN

Is end of input reached ?

require

  • is_connected

connect_to (directory_path: STRING)

Try to connect Current to some existing directory_path. After this call, the client is supposed to use is_connected to check that the stream is ready to be used.

require

  • not is_connected
  • not directory_path.is_empty
  • common_buffer_protection: last_entry /= directory_path

ensure

  • is_connected implies not end_of_input

connect_with (some_path: STRING)

Try to connect Current to some directory using some_path which may be either an existing directory path or some arbitrary file path name. When some_path is the path of some readable existing directory, this directory is opened and the effect of connect_with is equivalent to connect_to. When some_path is not an existing readable directory path, connect_with tries to open the directory which may contains some_path viewed as a file path name. After this call, the client is supposed to use is_connected to check that the stream is ready to be used and the last_entry buffer to know about the corresponding opened directory path. Whatever the result, some_path is left unchanged.

require

  • not is_connected
  • not some_path.is_empty
  • common_buffer_protection: last_entry /= some_path

ensure

  • is_connected implies not end_of_input

connect_to_current_working_directory

Try to connect Current to the current working directory. After this call, the client is supposed to use is_connected to check that the stream is ready to be used and the last_entry buffer to know about the name of the current working directory.

require

  • not is_connected

ensure

  • is_connected implies not end_of_input

disconnect

Do not forget to call this feature when you have finished with some previously opened directory stream.

require

  • is_connected

ensure

  • not is_connected

last_entry: STRING

Unique global buffer (once object) to get the last information computed by many routines of this class: read_entry, connect_with connect_to_current_working_directory, compute_parent_directory_of, ...

read_entry

Read the next entry name and update last_entry and end_of_input accordingly.

require

  • is_connected
  • not end_of_input

compute_parent_directory_of (some_path: STRING)

Using some_path (which may be either a file path or a directory path) tries to compute in the last_entry buffer the parent directory of some_path. When some_path is a path with no parent directory, the last_entry buffer is_empty after this call. This operation does not perform any disk access.

require

  • not some_path.is_empty
  • common_buffer_protection: last_entry /= some_path

compute_subdirectory_with (parent_path: STRING, entry_name: STRING)

Try to compute in the last_entry buffer the new subdirectory path obtained when trying to concatenate smartly parent_path whith some entry_name. When this fails the last_entry buffer is_empty after this call. This operation does not perform any disk access. Whatever the result, parent_path and entry_name are left unchanged.

require

  • not parent_path.is_empty
  • not entry_name.is_empty
  • common_buffer_protection1: last_entry /= parent_path
  • common_buffer_protection2: last_entry /= entry_name

compute_file_path_with (parent_path: STRING, file_name: STRING)

Try to compute in the last_entry buffer the new file path obtained when trying to concatenate smartly parent_path whith some file_name. When this fails the last_entry buffer is_empty after this call. This operation does not perform any disk access. Whatever the result, parent_path and file_name are left unchanged.

require

  • not parent_path.is_empty
  • not file_name.is_empty
  • common_buffer_protection1: last_entry /= parent_path
  • common_buffer_protection2: last_entry /= file_name

compute_absolute_file_path_with (path: STRING)

Try to compute an absolute path equivalent to path and store it in last_entry. When this fails the last_entry buffer is_empty after this call. This operation does not perform any disk access. Whatever the result, path is left unchanged.

require

  • valid_path(path)
  • common_buffer_protection: last_entry /= path

ensure

  • last_entry.is_empty or else system_notation.is_absolute_path(last_entry)

valid_path (path: STRING): BOOLEAN

Is the syntax of path valid for the system notation?

ensure

  • system_notation_detected implies Result = system_notation.is_valid_path(path)
  • not system_notation_detected implies Result = not path.is_empty

change_current_working_directory (directory_path: STRING)

Try to change the current working directory using some directory_path. When the operation is possible, the last_entry buffer is updated with the new current working directory path, otherwise, when the modification is not possible the last_entry buffer is_empty after this call. Whatever the result, directory_path is left unchanged.

require

  • not is_connected
  • common_buffer_protection1: last_entry /= directory_path

ensure

  • not is_connected

current_working_directory: STRING

The current working directory. Always returns the same once STRING.

create_new_directory (directory_path: STRING): BOOLEAN

Try to create a new directory using the directory_path name. Returns True on success.

require

  • not is_connected

ensure

  • not is_connected

remove_directory (directory_path: STRING): BOOLEAN

Try to remove directory directory_path which must be empty. Returns True on success.

require

  • not is_connected

ensure

  • not is_connected

remove_files_of (directory_path: STRING)

Try to remove all files (not subdirectories) of directory specified by directory_path.

require

  • not is_connected

ensure

  • not is_connected

remove_recursively (directory_path: STRING): BOOLEAN

Try to remove all files and all subdirectories of directory specified by directory_path.

require

  • not is_connected

ensure

  • not is_connected

is_case_sensitive: BOOLEAN
system_notation: DIRECTORY_NOTATION
system_notation_buffer: REFERENCE [E_][DIRECTORY_NOTATION]

Unique common buffer to memorize the system path notation

system_notation_detected: BOOLEAN
unix_notation: BOOLEAN

The Unix like file path notation looks like:

  /SmartEiffel/sys/system.se

windows_notation: BOOLEAN

The Windows like file path notation looks like:

  C:\SmartEiffel\sys\system.se

cygwin_notation: BOOLEAN

The Cygwin like file path notation looks like:

  //C/SmartEiffel/sys/system.se

amiga_notation: BOOLEAN

The Amiga file path notation looks like:

  DEV:SmartEiffel/sys/system.se

macintosh_notation: BOOLEAN

The Macintosh file path notation looks like:

  :SmartEiffel:sys:system.se

openvms_notation: BOOLEAN

The VMS file path notation looks like:

   DISK:[SmartEiffel.sys]system.se
The current working directory notation is:
   DISK:[]
The equivalent of Unix .. is :
   [-]
The equivalent of Unix ../.. is :
   [-.-]

set_notation_using (some_path: STRING)

Try to detect automatically the file system notation.

require

  • not some_path.is_empty
  • not system_notation_detected

reset_notation_using (some_path: STRING)

Try to detect automatically the file system notation.

tmp_path: STRING
directory_open (path_pointer: POINTER): POINTER

Try to open some existing directory using path. When Result is_not_null, the directory is correctly opened and Result is a valid handle for this directory. Using Result, one can then scan the content of the directory using function basic_directory_read_entry and basic_directory_get_entry_name. Finally, a is_not_null directory must be closed using function basic_directory_close.

require

  • path_pointer.is_not_null

directory_read_entry (dirstream: POINTER): POINTER

Read an return a new entry using the directory handle dirstream obtained with function basic_directory_open. When there is no more entry, the Result becomes is_null.

require

  • dirstream.is_not_null

directory_get_entry_name (entry: POINTER): POINTER

Read an return a new entry using the directory handle dirstream obtained with function basic_directory_open. When there is no more entry, the Result becomes is_null.

require

  • entry.is_not_null

directory_close (dirstream: POINTER): BOOLEAN

Try to close some opened dirstream directory. A True result indicates that the directory is correctly closed.

require

  • dirstream.is_not_null

directory_current_working_directory: POINTER

Try to get the current working directory path.

directory_chdir (destination: POINTER): BOOLEAN

Try to change the current working directory using destination.

directory_mkdir (directory_path: POINTER): BOOLEAN

Try to create a new directory using directory_path.

directory_rmdir (directory_path: POINTER): BOOLEAN

Try to remove directory_path.