class EL_FILE_PATH

(source code)

Client examples: ADD_ALBUM_ART_TASKADD_ALBUM_ART_TASK_TEST_SETAMAZON_INSTANT_ACCESS_TEST_SETARCHIVE_FILEARCHIVE_SONGS_TASKAUDIO_COMMAND_TEST_SETBENCHMARK_HTMLBINARY_BUILDER_FACTORYBINARY_DECODE_APPBUILDER_FACTORYCAD_MODELCAD_MODEL_SLICERCHECK_LOCALE_STRINGS_COMMANDCLASS_DESCENDANTS_COMMANDCLASS_FILE_NAME_NORMALIZERCLASS_LINKCLASS_LINK_LISTCLASS_NOTESCLASS_RENAMING_COMMANDCLASS_RENAMING_SHELL_COMMAND

description

Path to a file

notes

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