.TH "Filename" 3o source: 2019-01-25 OCamldoc "OCaml library" .SH NAME Filename \- Operations on file names. .SH Module Module Filename .SH Documentation .sp Module .BI "Filename" : .B sig end .sp Operations on file names\&. .sp .sp .sp .I val current_dir_name : .B string .sp The conventional name for the current directory (e\&.g\&. .B \&. in Unix)\&. .sp .I val parent_dir_name : .B string .sp The conventional name for the parent of the current directory (e\&.g\&. .B \&.\&. in Unix)\&. .sp .I val dir_sep : .B string .sp The directory separator (e\&.g\&. .B / in Unix)\&. .sp .B "Since" 3.11.2 .sp .I val concat : .B string -> string -> string .sp .B concat dir file returns a file name that designates file .B file in directory .B dir \&. .sp .I val is_relative : .B string -> bool .sp Return .B true if the file name is relative to the current directory, .B false if it is absolute (i\&.e\&. in Unix, starts with .B / )\&. .sp .I val is_implicit : .B string -> bool .sp Return .B true if the file name is relative and does not start with an explicit reference to the current directory ( .B \&./ or .B \&.\&./ in Unix), .B false if it starts with an explicit reference to the root directory or the current directory\&. .sp .I val check_suffix : .B string -> string -> bool .sp .B check_suffix name suff returns .B true if the filename .B name ends with the suffix .B suff \&. .sp .I val chop_suffix : .B string -> string -> string .sp .B chop_suffix name suff removes the suffix .B suff from the filename .B name \&. The behavior is undefined if .B name does not end with the suffix .B suff \&. .sp .I val extension : .B string -> string .sp .B extension name is the shortest suffix .B ext of .B name0 where: .sp .sp \- .B name0 is the longest suffix of .B name that does not contain a directory separator; .sp \- .B ext starts with a period; .sp \- .B ext is preceded by at least one non\-period character in .B name0 \&. If such a suffix does not exist, .B extension name is the empty string\&. .sp .B "Since" 4.04 .sp .I val remove_extension : .B string -> string .sp Return the given file name without its extension, as defined in .B Filename\&.extension \&. If the extension is empty, the function returns the given file name\&. .sp The following invariant holds for any file name .B s : .sp .B remove_extension s ^ extension s = s .sp .B "Since" 4.04 .sp .I val chop_extension : .B string -> string .sp Same as .B Filename\&.remove_extension , but raise .B Invalid_argument if the given name has an empty extension\&. .sp .I val basename : .B string -> string .sp Split a file name into directory name / base file name\&. If .B name is a valid file name, then .B concat (dirname name) (basename name) returns a file name which is equivalent to .B name \&. Moreover, after setting the current directory to .B dirname name (with .B Sys\&.chdir ), references to .B basename name (which is a relative file name) designate the same file as .B name before the call to .B Sys\&.chdir \&. .sp This function conforms to the specification of POSIX\&.1\-2008 for the .B basename utility\&. .sp .I val dirname : .B string -> string .sp See .B Filename\&.basename \&. This function conforms to the specification of POSIX\&.1\-2008 for the .B dirname utility\&. .sp .I val temp_file : .B ?temp_dir:string -> string -> string -> string .sp .B temp_file prefix suffix returns the name of a fresh temporary file in the temporary directory\&. The base name of the temporary file is formed by concatenating .B prefix , then a suitably chosen integer number, then .B suffix \&. The optional argument .B temp_dir indicates the temporary directory to use, defaulting to the current result of .B Filename\&.get_temp_dir_name \&. The temporary file is created empty, with permissions .B 0o600 (readable and writable only by the file owner)\&. The file is guaranteed to be different from any other file that existed when .B temp_file was called\&. Raise .B Sys_error if the file could not be created\&. .sp .B "Before3.11.2" no ?temp_dir optional argument .sp .I val open_temp_file : .B ?mode:Pervasives.open_flag list -> .B ?perms:int -> .B ?temp_dir:string -> string -> string -> string * Pervasives.out_channel .sp Same as .B 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 than .B temp_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 argument .B mode is a list of additional flags to control the opening of the file\&. It can contain one or several of .B Open_append , .B Open_binary , and .B Open_text \&. The default is .B [Open_text] (open in text mode)\&. The file is created with permissions .B perms (defaults to readable and writable only by the file owner, .B 0o600 )\&. .sp .B "Before4.03.0" no ?perms optional argument .sp .B "Before3.11.2" no ?temp_dir optional argument .sp .B "Raises Sys_error" if the file could not be opened\&. .sp .I val get_temp_dir_name : .B unit -> string .sp The name of the temporary directory: Under Unix, the value of the .B TMPDIR environment variable, or "/tmp" if the variable is not set\&. Under Windows, the value of the .B TEMP environment variable, or "\&." if the variable is not set\&. The temporary directory can be changed with .B Filename\&.set_temp_dir_name \&. .sp .B "Since" 4.00.0 .sp .I val set_temp_dir_name : .B string -> unit .sp Change the temporary directory returned by .B Filename\&.get_temp_dir_name and used by .B Filename\&.temp_file and .B Filename\&.open_temp_file \&. .sp .B "Since" 4.00.0 .sp .I val temp_dir_name : .B string .sp .B "Deprecated." You should use .B Filename\&.get_temp_dir_name instead\&. .sp The name of the initial temporary directory: Under Unix, the value of the .B TMPDIR environment variable, or "/tmp" if the variable is not set\&. Under Windows, the value of the .B TEMP environment variable, or "\&." if the variable is not set\&. .sp .B "Since" 3.09.1 .sp .I val quote : .B string -> string .sp Return a quoted version of a file name, suitable for use as one argument in a command line, escaping all meta\-characters\&. Warning: under Windows, the output is only suitable for use with programs that follow the standard Windows quoting conventions\&. .sp