如何检查perl中的目录是否为空?

时间:2014-10-02 03:13:11

标签: perl

检查目录是否为空的简单方法是什么?     $ directory =" / my_directory" 我只想检查$ directory是否为空,或者是否有任何文件,或者是否有任何具有特定扩展名的文件,例如* .txt。

1 个答案:

答案 0 :(得分:0)

我不知道Perl,所以这个答案并不完整。

// Create an integer variable that is initially set to 0.
opendir ( DIR, $dirname )
// Check if opendir failed. Return whatever value you think is appropriate.
while( ($filename = readdir(DIR))){
    // Increment integer variable
}
// Check if integer variable is 0.

这至少可以让你开始。

相关问题