package fileutils

  1. Overview
  2. Docs

Module FilePathSource

Operations on abstract filenames.

This module allow to manipulate string or abstract representation of a filename.

Abstract representation of a filename allow to decode it only once, and should speed up further operation on it (comparison in particular). If you intend to do a lot of processing on filename, you should consider using its abstract representation.

This module manipulate abstract path that are not bound to a real filesystem. In particular, it makes the assumption that there is no symbolic link that should modify the meaning of a path. If you intend to use this module against a real set of filename, the best solution is to apply to every filename to solve symbolic link through FileUtil.readlink.

  • author Sylvain Le Gall
Sourcetype filename = string

Filename type.

Sourcetype extension = string

Extension type.

Exceptions and types

Sourceexception BaseFilenameRelative of filename

Cannot pass a base filename which is relative.

Sourceexception UnrecognizedOS of string

We do not have recognized any OS, please contact upstream.

Sourceexception EmptyFilename

The filename use was empty.

Sourceexception NoExtension of filename

The last component of the filename does not support extension (Root, ParentDir...)

Sourceexception InvalidFilename of filename

The filename used is invalid.

Ordering

Sourceval is_subdir : filename -> filename -> bool

is_subdir fl1 fl2 Is fl2 a sub directory of fl1

Sourceval is_updir : filename -> filename -> bool

is_updir fl1 fl2 Is fl1 a sub directory of fl2

Sourceval compare : filename -> filename -> int

compare fl1 fl2 Give an order between the two filename. The classification is done by sub directory relation, fl1 < fl2 iff fl1 is a subdirectory of fl2, and lexicographical order of each part of the reduce filename when fl1 and fl2 has no hierarchical relation

Standard operations

Sourceval current_dir : filename

Current dir.

Sourceval parent_dir : filename

Upper dir.

Sourceval make_filename : string list -> filename

Make a filename from a set of strings.

Sourceval basename : filename -> filename

Extract only the file name of a filename.

Sourceval dirname : filename -> filename

Extract the directory name of a filename.

Sourceval concat : filename -> filename -> filename

Append a filename to a filename.

Sourceval reduce : ?no_symlink:bool -> filename -> filename

Return the shortest filename which is equal to the filename given. It remove the "." in Unix filename, for example. If no_symlink flag is set, consider that the path doesn't contain symlink and in this case ".." for Unix filename are also reduced.

Sourceval make_absolute : filename -> filename -> filename

Create an absolute filename from a filename relative and an absolute base filename.

Sourceval make_relative : filename -> filename -> filename

Create a filename which is relative to the base filename.

Sourceval reparent : filename -> filename -> filename -> filename

reparent fln_src fln_dst fln Return the same filename as fln but the root is no more fln_src but fln_dst. It replaces the fln_src prefix by fln_dst.

Sourceval identity : filename -> filename

Identity for testing the stability of implode/explode.

Sourceval is_valid : filename -> bool

Test if the filename is a valid one.

Sourceval is_relative : filename -> bool

Check if the filename is relative to a dir or not.

Sourceval is_current : filename -> bool

Check if the filename is the current directory.

Sourceval is_parent : filename -> bool

Check if the filename is the parent directory.

Extension

Extension is define as the suffix of a filename, just after the last ".".

Sourceval chop_extension : filename -> filename

Remove extension and the trailing ".".

Sourceval get_extension : filename -> extension

Extract the extension.

Sourceval check_extension : filename -> extension -> bool

Check the extension.

Sourceval add_extension : filename -> extension -> filename

Add an extension with a "." before.

Sourceval replace_extension : filename -> extension -> filename

Replace extension.

PATH-like operation

PATH-like refers the environment variable PATH. This variable holds a list of filename. The functions string_of_path and path_of_string allow to convert this kind of list by using the good separator between filename.

Sourceval string_of_path : filename list -> string

Create a PATH-like string.

Sourceval path_of_string : string -> filename list

Extract filenames from a PATH-like string.

Filename specifications

Definition of operations for path manipulation.

Sourcemodule type PATH_SPECIFICATION = sig ... end

Generic operations.

Sourcemodule type PATH_STRING_SPECIFICATION = sig ... end

Generic operations, with type filename and extension as strings.

Operations on filenames for other OS. The DefaultPath always match the current OS.

Default operating system.

Unix operating system.

Win32 operating system.

Cygwin operating system.

OCaml

Innovation. Community. Security.