即時通訊嘗試檢查是否存在比X minuts更早的文件(我不在乎文件夾)。不幸的是,我可以;不知道我的代碼在哪裏。 我將所有並欣賞幫助:)Perl:找到超過X分鐘數的文件的最快方法,將最舊到最新排序
1.找到比分鐘
#!/usr/bin/perl
my $maindir = "C:\\Users\\Dor\\Desktop\\aba";
my $minutesold = 60;
my $now = time;
my $filedisc;
# Declare arrays
my @xmlfiles;
my @qulfiedfiles;
# Declare a Dictionary
my %filedisc;
opendir(my $dh, $maindir) or die "opendir($maindir): $!";
# Read all the files
while (my $de = readdir($dh))
{
# get the Full path of the file
my $f = $maindir . $de;
if (-f $f)
{
push (@xmlfiles, $f);
}
}
closedir($dh);
# For every file in directory
for my $file (@xmlfiles) {
# Get stats about a file
my @stats = stat($file);
# If time stamp is older than minutes provided
if ($stats[9] >= ($now - (($minutesold * 60)))){
# Put the File and Time stamp in the dictionary
print($stats[9] ." .| " .$file ."\n\n");
}
#print($now ."\n")
#print($now - ($minutesold * 60) ."\n");
}
當你運行它什麼不順心?你看過@xmlfiles並驗證了正確的文件名被添加到它嗎? – ysth
像'#Declare arrays'這樣的東西很荒謬。如果你看不到接下來的內容,那麼你就沒有理解代碼和意見的希望。已經過了20年或更長的時間,只是爲了說明而留下您的代碼,最好使用合理的標識符來表達您的想法。只有當代碼模糊或者沒有經驗(可能是由於優化),或者當代碼不清楚時,您才需要註釋。既不適用於此代碼中的任何評論,所以它們僅用於掩蓋它。 '#讀取所有文件'完全錯誤。 – Borodin