Create Erlang Directory

I need to create a subdirectory in a specific directory.

In erlang docs I only find the file: make_dir / 1, which creates a directory in the project's source directory. How to create a directory in another directory?

I find a solution. Maybe it will be interesting to someone:

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

Thanks.

+4
source share
2 answers

You can guarantee that the directory exists (and create it if it does not, and what you are looking for) with filelib:ensure_dir .

Example:

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

Literature:

+11
source

The documentation should be unclear, since you can use file:make_dir/1 to create any directory that you usually allow to create. It does not create all the directories in the path, you must do this explicitly yourself.

Using filelib:ensure_dir/1 with the end ending with "/" is not documented, but it is explicitly processed in the code, so I doubt it will disappear.

+2
source

Source: https://habr.com/ru/post/1336580/


All Articles