查找系列中丢失文件的代码

发布于 2024-09-10 11:54:51 字数 166 浏览 1 评论 0原文

我正在寻找一行代码来识别一系列文件中丢失的文件并将该列表导出到 txt 文件。例如:名为 1to100000 的目录包含名为 1,2...99999,100000 的 pdf 文件,但缺少该系列中的一些文件。我希望脚本将这些丢失的文件报告到 txt 文件。理想情况下,这将是一个可执行的 perl 脚本。 谢谢, 杰克

I'm looking for a line of code that identifies missing files in a series of files and exports that list to a txt file. For example: a directory called 1to100000 contains pdfs named 1,2...99999,100000 but is missing some from the series. I would like the script to report those missing files to a txt file. Ideally this would be an executable perl script.
Thanks,
Jake

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贪恋 2024-09-17 11:54:51

只需从 1 数到 100000 并检查文件是否存在。

foreach my $num ( 1 .. 100000 ) { 
    my $fname = "1to100000/$num.pdf";
    print "missing $fname\n" unless -f $fname;
}

Just count from 1 to 100000 and check to see if the file exists.

foreach my $num ( 1 .. 100000 ) { 
    my $fname = "1to100000/$num.pdf";
    print "missing $fname\n" unless -f $fname;
}
太阳公公是暖光 2024-09-17 11:54:51

使用readdir:

my @expect = map "$_.pdf", 1..100000;
my %notfound;
@notfound{@expect} = ();

opendir my $dirh, "1to100000" or die "Couldn't open directory: $!";
while ( my $fname = readdir($dirh) ) {
    delete $notfound{$fname};
}

for my $fname (@expect) {
    if ( exists $notfound{$fname} ) {
        print "missing $fname\n";
    }
}

Using readdir:

my @expect = map "$_.pdf", 1..100000;
my %notfound;
@notfound{@expect} = ();

opendir my $dirh, "1to100000" or die "Couldn't open directory: $!";
while ( my $fname = readdir($dirh) ) {
    delete $notfound{$fname};
}

for my $fname (@expect) {
    if ( exists $notfound{$fname} ) {
        print "missing $fname\n";
    }
}
暖阳 2024-09-17 11:54:51

以下是查找范围内缺失数字的示例(使用 Set::IntSpan)。

#!/usr/bin/perl
use strict;
use warnings;

use Set::IntSpan;

# the last sector on disk
my $end_sect = 71127179;

# The complete range of sectors on the disk
my $range = Set::IntSpan->new( "0-$end_sect" );

# The ranges of used sectors
my $used = Set::IntSpan->new( 
'0-1048706,1048707-2097414,69078879-71127179' );

# Calculates the remaining unused sectors
my $unused = $range->diff( $used );

print $unused->run_list;

Here is an example of finding missing numbers in a range (Using Set::IntSpan).

#!/usr/bin/perl
use strict;
use warnings;

use Set::IntSpan;

# the last sector on disk
my $end_sect = 71127179;

# The complete range of sectors on the disk
my $range = Set::IntSpan->new( "0-$end_sect" );

# The ranges of used sectors
my $used = Set::IntSpan->new( 
'0-1048706,1048707-2097414,69078879-71127179' );

# Calculates the remaining unused sectors
my $unused = $range->diff( $used );

print $unused->run_list;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文