Module ce_file

File manipulation library.

Description

File manipulation library.

Function Index

add_pathz_libdirs/1Adds all the subdirectories of the given directories to the library search path.
app_name/1Returns the application portion of an application directory name.
app_version/1Returns the version portion of an application directory name.
complete/1Equivalent to complete(filename:dirname(string()), filename:basename(string())).
complete/2Given the name of a directory and a prefix (of any length) of a file or files in that directory, returns the file or files that the prefix matches, if any.
create/2Equivalent to create(filename(), length(), 0).
create/3Creates an empty file of a given length, padded with a given value.
dump/2Writes all terms to a file.
each_line/3Iterates over a text file.
exists/1Checks whether a file or directory exists.
find/3Finds files, filters them, and executes a callback for each one.
import/4Provides a very generic interface for importing fields from files.
import_columns/4Imports fields from a columnar text file.
import_fields/5Imports fields from a CSV-like file.
is_binary/1Makes an educated guess as to whether the file is binary (as opposed to plain ASCII text).
is_dir/1Checks whether a file is a directory.
is_world_executable/1Checks whether a file is executable by the entire world.
is_world_readable/1Checks whether a file is readable by the entire world.
is_world_writeable/1Checks whether a file is writeable by the entire world.
last_modified/1Returns the local date and time the file was last modified.
size/1Returns the size of a file, in bytes.
slurp/1Returns the entire text file as a list of strings.

Function Details

add_pathz_libdirs/1

add_pathz_libdirs(LibDirs::[dirname()]) -> ok | {error, Reason}

Adds all the subdirectories of the given directories to the library search path. This uses code:add_pathz and is intended to be called from a .erlang file or other startup file.

app_name/1

app_name(FileName::filename()) -> string()

Returns the application portion of an application directory name. Everything after the last hyphen is stripped. e.g. ce_file:app_name("/usr/local/lib/erlang/lib/foo-2.3") -> "foo"

app_version/1

app_version(FileName::filename()) -> string()

Returns the version portion of an application directory name. Everything before the last hyphen is stripped. e.g. ce_file:app_name("/usr/local/lib/erlang/lib/foo-1.9") -> "1.9"

complete/1

complete(PartialFileName::string()) -> {ok, filename()} | {ambiguous, [filename()]} | {error, Reason}

Equivalent to complete(filename:dirname(string()), filename:basename(string())).

complete/2

complete(DirName::dirname(), PartialFileName::string()) -> {ok, filename()} | {ambiguous, [filename()]} | {error, Reason}

Given the name of a directory and a prefix (of any length) of a file or files in that directory, returns the file or files that the prefix matches, if any. e.g. ce_file:complete("/usr/local/", "e") -> {ok, "/usr/local/etc"}

create/2

create(FileName::filename(), Length::length()) -> ok | {error, Reason}

Equivalent to create(filename(), length(), 0).

create/3

create(FileName::filename(), Length::length(), Pad::byte()) -> ok | {error, Reason}

Creates an empty file of a given length, padded with a given value.

dump/2

dump(Filename::filename(), List::[term()]) -> {ok, [term()]} | {error, Reason}

Writes all terms to a file. Complements file:consult/1.

each_line/3

each_line(Fun::'fun'(), Acc::term(), FileName::filename()) -> term()

Iterates over a text file. Thanks to Klacke for the general idea.

exists/1

exists(FileName::filename()) -> true | false

Checks whether a file or directory exists. Unlike previous incarnations, this literally checks whether the file exists, i.e. whether it's file information can be read.

find/3

find(Dir::dir(), Pred::pred(), Action::action()) -> [term()] | {error, {File, Reason}}

Finds files, filters them, and executes a callback for each one. dir() is the top directory where everything starts. pred() is a fun/1 which takes a filename and returns true if it is to be listed. action() is a fun/1 to apply to each found file which matches the predicate. Both funs are passed the full file name (up to but not including the top) as parameter. Return value is a list of the return values from the action() fun. Thanks to Klacke for providing the origin of this function.

import/4

import(Fun::'fun'(), Acc::term(), FileName::filename(), FileSchema::fileschema()) -> term()

Provides a very generic interface for importing fields from files.

import_columns/4

import_columns(Fun::'fun'(), Acc::term(), FileName::filename(), Schema::lineschema()) -> term()

Imports fields from a columnar text file. Schema is a list of {Column,Width} tuples.

import_fields/5

import_fields(Fun::'fun'(), Acc::term(), FileName::filename(), Delim::string(), Quote::string()) -> term()

Imports fields from a CSV-like file.

is_binary/1

is_binary(Filename::filename()) -> true | false | {error, Reason}

Makes an educated guess as to whether the file is binary (as opposed to plain ASCII text). The heuristic used is similar to that of grep and Perl's -B operator. The first 32K of the file is examined for odd characters such as strange control codes or characters with the high bit set. If too many strange characters (>30%) are found, or if any zero bytes (nulls) are encountered, the file is considered binary.

is_dir/1

is_dir(Filename::filename()) -> true | false

Checks whether a file is a directory. Thanks to James Hague.

is_world_executable/1

is_world_executable(Filename::filename()) -> true | false

Checks whether a file is executable by the entire world.

is_world_readable/1

is_world_readable(Filename::filename()) -> true | false

Checks whether a file is readable by the entire world.

is_world_writeable/1

is_world_writeable(Filename::filename()) -> true | false | {error, Reason}

Checks whether a file is writeable by the entire world.

last_modified/1

last_modified(Filename::filename()) -> {date(), time()}

Returns the local date and time the file was last modified.

size/1

size(Filename::filename()) -> integer()

Returns the size of a file, in bytes.

slurp/1

slurp(FileName::filename()) -> [string()]

Returns the entire text file as a list of strings. This is not a particularly scaleable solution, and is not recommended on large files.


Generated by EDoc, Dec 25 2007, 02:37:24.