How to create a directory, but delete it if it already exists in Perl?

I would like to create a dir, but if it already exists, I would like to delete it first (along with all its contents).

Should I explicitly add if (-d ...)or is there a simpler mkdirone that already does this?

+3
source share
1 answer

You can use functions from the main module File :: Path :

use File::Path qw(make_path remove_tree);

remove_tree('foo/bar/baz');
make_path('foo/bar/baz');
+10
source

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


All Articles