Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang create directory

I need create subdirectory in specific directory.

In erlang docs i find only file:make_dir/1 which create dir in the project source dir. How can i create directory in other dir?

I find solution. Maybe it will be interesting somebody:

filelib:ensure_dir("/this/path/will/soon/exist/").

Thank you.

like image 437
0xAX Avatar asked Jan 22 '11 13:01

0xAX


2 Answers

You can ensure that a directory exists (and create it if it doesn't, which is what you're looking for) using filelib:ensure_dir.

Example:

filelib:ensure_dir("/this/path/will/soon/exist/")

References:

  • filelib:ensure_dir documentation
like image 153
Sebastian Paaske Tørholm Avatar answered Sep 17 '22 11:09

Sebastian Paaske Tørholm


The documentation must have been unclear as you can use file:make_dir/1 to create any directory which you would normally be allowed to create. It does not create all directories in the path, this you have to do explicitly yourself.

Using filelib:ensure_dir/1 with a path terminated by "/" is not documented but it is explicitly handled in the code so I doubt that it will go away.

like image 30
rvirding Avatar answered Sep 20 '22 11:09

rvirding