开发者

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

开发者 https://www.devze.com 2022-12-19 21:19 出处:网络
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开发者_开发百科 someh

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?


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.


@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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消