class EL_FILE_PATH
Client examples: ADD_ALBUM_ART_TASK ; ADD_ALBUM_ART_TASK_TEST_SET ; AMAZON_INSTANT_ACCESS_TEST_SET ; ARCHIVE_FILE ; ARCHIVE_SONGS_TASK ; AUDIO_COMMAND_TEST_SET ; BENCHMARK_HTML ; BINARY_BUILDER_FACTORY ; BINARY_DECODE_APP ; BUILDER_FACTORY ; CAD_MODEL ; CAD_MODEL_SLICER ; CHECK_LOCALE_STRINGS_COMMAND ; CLASS_DESCENDANTS_COMMAND ; CLASS_FILE_NAME_NORMALIZER ; CLASS_LINK ; CLASS_LINK_LIST ; CLASS_NOTES ; CLASS_RENAMING_COMMAND ; CLASS_RENAMING_SHELL_COMMAND
Path to a file
Short alias is FILE_PATH
note
description: "Path to a file"
notes: "Short alias is **FILE_PATH**"
author: "Finnian Reilly"
copyright: "Copyright (c) 2001-2022 Finnian Reilly"
contact: "finnian at eiffel hyphen loop dot com"
license: "MIT license (See: en.wikipedia.org/wiki/MIT_License)"
date: "2024-09-25 15:35:41 GMT (Wednesday 25th September 2024)"
revision: "42"
class
EL_FILE_PATH
inherit
EL_PATH
EL_MODULE_FILE
create
default_create, make, make_expanded, make_from_other, make_from_path, make_from_steps
-- Cannot use `to_general: {READABLE_STRING_GENERAL}' due to bug
-- in `{PLAIN_TEXT_FILE}.file_open' for non-ascii characters
convert
-- from
make ({ZSTRING, STRING, STRING_32, IMMUTABLE_STRING_8, IMMUTABLE_STRING_32}),
make_from_path ({PATH}),
-- to
to_string: {EL_ZSTRING}, as_string_32: {READABLE_STRING_GENERAL, READABLE_STRING_32},
steps: {EL_PATH_STEPS}, to_path: {PATH}, to_uri: {EL_URI}
feature -- Access
modification_time: INTEGER
do
Result := File.modification_time (Current)
end
relative_dot_path (other: FILE_PATH): FILE_PATH
-- relative path using dots do navigate from `other.parent' to `base'
-- Eg. ../../<base> OR ../bbb/<base> OR <base>
local
dot_dir, super_dir: DIR_PATH
do
if parent ~ other.parent then
Result := base
elseif parent.is_parent_of (other) then
create dot_dir.make (Directory.relative_parent (other.step_count - step_count))
Result := dot_dir + base
else
from super_dir := parent until super_dir.is_parent_of (Current) and super_dir.is_parent_of (other) loop
super_dir := super_dir.parent
end
create dot_dir.make (Directory.relative_parent (other.step_count - super_dir.step_count - 1))
Result := dot_dir.plus_file (relative_path (super_dir))
end
end
related (path: like Current; new_extension: READABLE_STRING_GENERAL): like Current
-- if `path' is empty result is same as `Current' but with extension `new_extension'
-- otherwise `path'
do
if path.is_empty then
Result := with_new_extension (new_extension)
else
Result := path
end
end
relative_path (a_parent: DIR_PATH): FILE_PATH
do
create Result.make (relative_temporary_path (a_parent))
end
type_alias: ZSTRING
-- localized description
do
Result := Word.file
end
feature -- Conversion
to_ntfs_compatible (c: CHARACTER): like Current
-- NT file system compatible path string using `c' to substitue invalid characters
local
ntfs: EL_NT_FILE_SYSTEM_ROUTINES
do
Result := ntfs.translated (Current, c)
end
feature -- Status report
Is_directory: BOOLEAN = False
is_pattern: BOOLEAN
-- `True' if base is a wildcard pattern
do
Result := base.starts_with_general ("*.") and base.count > 2
end
feature {NONE} -- Implementation
new_path (a_path: ZSTRING): like Current
do
create Result.make (a_path)
end
end