0
使文件之間的差異文件大小的基礎上,我寫一個腳本,我有3個一級目錄如下圖所示:如何在Perl
LOG
├── a.txt
├── b.txt
└── sdlog
├── 1log
│ ├── a.txt
│ └── b.txt
└── 2log
├── a.txt
└── b.txt
的文件的名稱是相同的,但規模將始終差異。我必須在LOG
dir和1log
dir的大小的基礎上比較這些文件。那些在2log
中的文件我們不會做任何事情。
我已經寫了這些打印的文件名稱,但不能以上任務的腳本:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::Basename;
my $new_file_name;
my $start_directory = "C:\\logs";
find({ wanted => \&renamefile }, $start_directory);
sub renamefile
{
if (-f and /\.txt$/)
{
my $file = $_;
open (my $rd_fh, "<", $file);
LINE: while (<$rd_fh>)
{
if (/<(\d)>/i)
{
close $rd_fh;
print"$file\n";
#print" Kernal-> $file\n";
last LINE;
}
if (/I\/am_create_activity/i)
{
close $rd_fh;
print"$file\n";
#print" EVENT-> $file\n";
last LINE;
}
}
}
}
使用'-s'來獲取文件的大小。請說明你想達到的目標。 – choroba
我的目的是將Dir-> LOG-> a.txt,b.txt與subdir-> 1log-> a.txt,b.txt進行比較。文件大小我想要那個文件。 – Maverick