有什麼方法可以保證readdir
返回列表中的訂單嗎?Perl readdir以訂購
我的代碼:
opendir(my $DIR, $src) or die "Error opening $src";
# Loop for each file in the directory
while (my $file = readdir($DIR))
{
print "$file\n";
}
但它以隨機順序返回。現在我知道有很多解決方案通過快速Google搜索,但我找不到我需要的確切順序。 基本上我希望文件夾出現在FIRST或LAST中,而不是在文件之間。
例如,現在如果我有文件夾結構:
folder
folder
file1
file2
file3
我得到的結果是:
file2
folder
folder
file1
file3
當我真的想:
folder
folder
file1
file2
file3
或者:
file1
file2
file3
folder
folder
任何方式來實現這一目標?
謝謝。
應使用某種形式的。 –