3

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?

1 Answer 1

10

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');
Sign up to request clarification or add additional context in comments.

1 Comment

It's quite annoying that I can't use `remove_tree($path) or die "...", but have to explicitly add a variable to capture an error and then check it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.