David B
David B

Reputation: 29998

How can I create a dir but remove it if it already exists in Perl?

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

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

Upvotes: 3

Views: 866

Answers (1)

Eugene Yarmash
Eugene Yarmash

Reputation: 149973

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

use File::Path qw(make_path remove_tree);

remove_tree('foo/bar/baz');
make_path('foo/bar/baz');

Upvotes: 10

Related Questions