View Source z_filelib (zotonic_stdlib v1.26.1)
Extra file functions to complement the standard library. Rename files between different filesystems, and ensure directories of a path exist. Also escape routines to safely handle filenames as command line arguments.
Summary
Functions
Ensure the directory of a file is present. This will still work if a soft-link in the path refers to a missing directory.
Simple escape function for command line arguments. Escapes special characters in the filename using backslashes. The path is not quoted, use os_filename/1 for that.
Simple escape function for filenames as commandline arguments. foo/"bar.jpg -> "foo/\"bar.jpg"; on windows "foo\\\"bar.jpg" (both including quotes!)
Rename a file. Copy the file on a cross-fs error.
Functions
-spec ensure_dir(file:filename_all()) -> ok | {error, term()}.
Ensure the directory of a file is present. This will still work if a soft-link in the path refers to a missing directory.
Simple escape function for command line arguments. Escapes special characters in the filename using backslashes. The path is not quoted, use os_filename/1 for that.
Simple escape function for filenames as commandline arguments. foo/"bar.jpg -> "foo/\"bar.jpg"; on windows "foo\\\"bar.jpg" (both including quotes!)
-spec rename(From, To) -> ok | {error, term()} when From :: file:filename_all(), To :: file:filename_all().
Rename a file. Copy the file on a cross-fs error.