Perl 删除目录中的所有文件 [英] Perl delete all files in a directory

查看:74
本文介绍了Perl 删除目录中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Perl 中删除所有目录中的文件(而不删除目录)?

How can I delete all the files in a directory, (without deleting the directory) in Perl?

我的主机只允许最多 250,000 个文件",我的/tmp 文件夹在所有会话 cookie 都在进行的情况下快速填充了 250,000 个 qouta.在这种情况下,我无法删除/tmp 文件夹.我只能删除其中的文件.

My host only allows up to 250,000 "files" and my /tmp folder fills that 250,000 qouta fast with all the session cookies going on. I cannot delete the /tmp folder in this situation. I am only permitted to delete the files within.

编辑:

FTP 客户端和文件管理器并不完全想打开该文件夹...我认为这是因为其中包含大量文件...

FTP clients and File managers don't exactly want to open up the folder... I assume it's because of the massive amount of files in it..

推荐答案

my $errors;
while ($_ = glob('/tmp/* /tmp/.*')) {
   next if -d $_;
   unlink($_)
      or ++$errors, warn("Can't remove $_: $!");
}

exit(1) if $errors;

这篇关于Perl 删除目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆