Lucas Meijer
Lucas Meijer

Reputation: 4484

perl's rmtree() failing to delete directory on win32, successful on second try

In Perl, I do a:

rmtree($myfolder);

Often this fails on windows. When ran again, it then succeeds. It seems like somehow it takes a while to delete the files in the folder, and somehow it tries to delete the folder before the files are gone.

Is there a "this one actually works" Perl method to erase an directory with all its contents on Windows?

Upvotes: 1

Views: 2913

Answers (3)

Adam Kennedy
Adam Kennedy

Reputation: 1612

I took over and greatly improved File::Remove a while back, which is a bit more extreme and paranoid about deleting things.

It might do what you want.

And if it doesn't let me know and I'll improve it.

Upvotes: 2

ghostdog74
ghostdog74

Reputation: 342649

@OP, whenever things happen, always check whether you can handle those errors. See perldoc File::Path. Under remove_tree(), you can use verbose and error => \$err to show you errors encountered.

Upvotes: 2

jamessan
jamessan

Reputation: 42707

Do you have a virus scanner running? If it's scanning a file, it has the file open. Windows won't let you delete files/directories that are open by another process.

Upvotes: 2

Related Questions