Directory and File Operations
Three functions in file
are used for directory
operations. list_dir(Dir)
is used to produce a list of
the files in Dir
, make_dir(Dir)
creates a new
directory, and del_dir(Dir)
deletes a
directory.
If we run list_dir
on the code directory that I’m using
to write this book, we’ll see something like the following:
| 1> cd("/home/joe/book/erlang/Book/code"). |
| /home/joe/book/erlang/Book/code |
| ok |
| 2> file:list_dir("."). |
| {ok,["id3_v1.erl~", |
| "update_binary_file.beam", |
| "benchmark_assoc.beam", |
| "id3_v1.erl", |
| "scavenge_urls.beam", |
| "benchmark_mk_assoc.beam", |
| "benchmark_mk_assoc.erl", |
| "id3_v1.beam", |
| "assoc_bench.beam", |
| "lib_misc.beam", |
| "benchmark_assoc.erl", |
| "update_binary_file.erl", |
| "foo.dets", ... |
Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.