opendir

戻る

列出一個(gè)目錄下的所有文件

# pro_list.pl use strict; my(%t,$file); opendir(BIN,"cgi-bin\\pro"); open(OUT,">perlpro_list.txt"); print OUT "filename=perpro_list.txt.\n"; while (defined ($file = readdir BIN ) ) { next if $file =~ /^\.\.?$/; print OUT "file==>$file\n"; } close(BIN); 運(yùn)行結(jié)果

input.pl(該程序的要點(diǎn)是使用opendir)

# input.pl use strict; use HTML::Template; my(%t,@fld,$n,$template,@loop); $t{tmpl} = 'input0.htm'; $t{htmfile} = 'index.html'; $template = HTML::Template->new(filename => $t{tmpl}); print "Please input the directory name="; chop($t{dir}=<STDIN>); opendir(DIR,"$t{dir}") or die "Can't opendir $t{dir}: $!"; while ( defined($t{file}=readdir(DIR)) ) { next if $t{file} =~ /^\.\.?$/; # skip . and .. if ( substr($t{file},-3) eq 'csv' ) { $t{NO1} = $t{file}; substr($t{NO1},-4) = ''; substr($t{NO1},0,9) = ''; $t{list}{$t{NO1}} = $t{file}; } } close(DIR); @loop = (); $t{N1} = 0; for $n ( sort {$a<=>$b} keys %{ $t{list} } ) { $t{N1}++; $t{file} = $t{list}{$n}; $t{N3} = '<a href="' . $t{file} . '">' . $t{file} . '</a>'; my %row = ( N1 => $t{N1}, N2 => $n, file => $t{N3} ); push(@loop, \%row); } $template->param(loop => \@loop); $template->param(dir => $t{dir}); open(OUT,">./$t{dir}/$t{htmfile}"); print OUT $template->output; close(OUT); print "The output file is ./$t{dir}/$t{htmfile}\n"; __END__;
戻る
绥中县| 井研县| 灌云县| 木里| 濮阳县| 彭山县| 南阳市| 阜城县| 米泉市| 嘉定区| 富源县| 宁国市| 巴南区| 黑河市| 石门县| 朝阳县| 泰兴市| 宜城市| 科技| 西丰县| 涟水县| 建平县| 二连浩特市| 来安县| 监利县| 金塔县| 福泉市| 旬阳县| 平陆县| 黑山县| 富宁县| 天水市| 秀山| 离岛区| 永胜县| 明溪县| 定边县| 玉山县| 新巴尔虎左旗| 广宗县| 正宁县|