Module Caml.Filename
val parent_dir_name : stringThe conventional name for the parent of the current directory (e.g.
..in Unix).
val concat : string -> string -> stringconcat dir filereturns a file name that designates filefilein directorydir.
val is_relative : string -> boolReturn
trueif the file name is relative to the current directory,falseif it is absolute (i.e. in Unix, starts with/).
val is_implicit : string -> boolReturn
trueif the file name is relative and does not start with an explicit reference to the current directory (./or../in Unix),falseif it starts with an explicit reference to the root directory or the current directory.
val check_suffix : string -> string -> boolcheck_suffix name suffreturnstrueif the filenamenameends with the suffixsuff.Under Windows ports (including Cygwin), comparison is case-insensitive, relying on
String.lowercase_ascii. Note that this does not match exactly the interpretation of case-insensitive filename equivalence from Windows.
val chop_suffix : string -> string -> stringchop_suffix name suffremoves the suffixsufffrom the filenamename. The behavior is undefined ifnamedoes not end with the suffixsuff.chop_suffix_optis thus recommended instead.
val chop_suffix_opt : suffix:string -> string -> string optionchop_suffix_opt ~suffix filenameremoves the suffix from thefilenameif possible, or returnsNoneif the filename does not end with the suffix.Under Windows ports (including Cygwin), comparison is case-insensitive, relying on
String.lowercase_ascii. Note that this does not match exactly the interpretation of case-insensitive filename equivalence from Windows.- since
- 4.08
val extension : string -> stringextension nameis the shortest suffixextofname0where:name0is the longest suffix ofnamethat does not contain a directory separator;extstarts with a period;extis preceded by at least one non-period character inname0.
If such a suffix does not exist,
extension nameis the empty string.- since
- 4.04
val remove_extension : string -> stringReturn the given file name without its extension, as defined in
Filename.extension. If the extension is empty, the function returns the given file name.The following invariant holds for any file name
s:remove_extension s ^ extension s = s- since
- 4.04
val chop_extension : string -> stringSame as
Filename.remove_extension, but raiseInvalid_argumentif the given name has an empty extension.
val basename : string -> stringSplit a file name into directory name / base file name. If
nameis a valid file name, thenconcat (dirname name) (basename name)returns a file name which is equivalent toname. Moreover, after setting the current directory todirname name(withSys.chdir), references tobasename name(which is a relative file name) designate the same file asnamebefore the call toSys.chdir.This function conforms to the specification of POSIX.1-2008 for the
basenameutility.
val dirname : string -> stringSee
Filename.basename. This function conforms to the specification of POSIX.1-2008 for thedirnameutility.
val temp_file : ?temp_dir:string -> string -> string -> stringtemp_file prefix suffixreturns the name of a fresh temporary file in the temporary directory. The base name of the temporary file is formed by concatenatingprefix, then a suitably chosen integer number, thensuffix. The optional argumenttemp_dirindicates the temporary directory to use, defaulting to the current result ofFilename.get_temp_dir_name. The temporary file is created empty, with permissions0o600(readable and writable only by the file owner). The file is guaranteed to be different from any other file that existed whentemp_filewas called. RaiseSys_errorif the file could not be created.- before 3.11.2
no ?temp_dir optional argument
val open_temp_file : ?mode:Stdlib.open_flag list -> ?perms:int -> ?temp_dir:string -> string -> string -> string * Stdlib.out_channelSame as
Filename.temp_file, but returns both the name of a fresh temporary file, and an output channel opened (atomically) on this file. This function is more secure thantemp_file: there is no risk that the temporary file will be modified (e.g. replaced by a symbolic link) before the program opens it. The optional argumentmodeis a list of additional flags to control the opening of the file. It can contain one or several ofOpen_append,Open_binary, andOpen_text. The default is[Open_text](open in text mode). The file is created with permissionsperms(defaults to readable and writable only by the file owner,0o600).- raises Sys_error
if the file could not be opened.
- before 4.03.0
no ?perms optional argument
- before 3.11.2
no ?temp_dir optional argument
val get_temp_dir_name : unit -> stringThe name of the temporary directory: Under Unix, the value of the
TMPDIRenvironment variable, or "/tmp" if the variable is not set. Under Windows, the value of theTEMPenvironment variable, or "." if the variable is not set. The temporary directory can be changed withFilename.set_temp_dir_name.- since
- 4.00.0
val set_temp_dir_name : string -> unitChange the temporary directory returned by
Filename.get_temp_dir_nameand used byFilename.temp_fileandFilename.open_temp_file.- since
- 4.00.0
val temp_dir_name : stringThe name of the initial temporary directory: Under Unix, the value of the
TMPDIRenvironment variable, or "/tmp" if the variable is not set. Under Windows, the value of theTEMPenvironment variable, or "." if the variable is not set.- deprecated
You should use
Filename.get_temp_dir_name instead.
- since
- 3.09.1