ファイル数を読むプログラム

戻る

あるディレクトリのすべてのExcelファイル数を読む # Obtain files in a directory # files_all.pl 2007.07.31 use strict; my (%t,$s_ref,$n,$n1,@fld,$file1); # Read setting data while(<DATA>){ if ( /^SQL/ ) { chomp; @fld = split(/==>/); $$s_ref{E_DIR} = $fld[1]; $$s_ref{T_DIR} = $fld[2]; } } close(DATA); # Do one by one ($s_ref) = sfiles($s_ref); # Making TXT file $t{file1} = $$s_ref{E_DIR} . '-files_all.txt'; $t{txt_file} = '../txt/' . $t{file1}; open(OUT,"> $t{txt_file}"); print "It is writing to the file $t{txt_file}\n"; print OUT "Filename is $t{file1}\n"; for $n1 ( 0 .. $#{ $$s_ref{files} } ) { $t{NO} = $n1 + 1; printf OUT ("FILE %4s ",$t{NO}); print OUT "==>",$$s_ref{files}[$n1]; print OUT "\n"; } close(OUT); sub sfiles { my($s_ref) = @_; my (%t); $t{Dir} = '../' . $$s_ref{E_DIR}; # Open the directory opendir(BIN,$t{Dir}) or die "Can't open $t{Dir}.\n"; # Deal with files one by one while (defined ($t{file} = readdir BIN) ) { next if $t{file} =~ /^\.\.?$/; push(@{ $$s_ref{files} },$t{file}); } closedir(BIN); return($s_ref); } __DATA__ C E_DIR T_DIR SQL==>WORK 2005==>txt
Excelファイルを分類 # Obtain files in a directory # files_div.pl 2007.07.31 use strict; my (%t,$s_ref,$n,$n1,@fld,$file1); # Read setting data while(<DATA>){ if ( /^NAME/ ) { @fld = split; @{ $$s_ref{NAME} } = @fld[1..$#fld]; } elsif (/^SQL/) { chomp; @fld = split(/==>/); $$s_ref{E_DIR} = $fld[1]; $$s_ref{T_DIR} = $fld[2]; } } close(DATA); # Do one by one for $n ( 0 .. $#{ $$s_ref{NAME} } ) { # Obtaining data from Excel files $$s_ref{NAME1} = $$s_ref{NAME}[$n]; ($s_ref) = sfiles($s_ref); } # Making TXT file $t{file1} = $$s_ref{E_DIR} . '-files_div.txt'; $t{txt_file} = '../txt/' . $t{file1}; open(OUT,"> $t{txt_file}"); print "It is writing to the file $t{txt_file}\n"; print OUT "Filename is $t{file1}\n"; for $n ( 0 .. $#{ $$s_ref{NAME} } ) { $t{NAME1} = $$s_ref{NAME}[$n]; for $n1 ( 0 .. $#{ $$s_ref{files}{$t{NAME1}} } ) { $t{NO} = $n1 + 1; print OUT $t{NAME1}, "==>",$t{NO}; print OUT "==>",$$s_ref{files}{$t{NAME1}}[$n1]; print OUT "\n"; } } close(OUT); sub sfiles { my($s_ref) = @_; my (%t); $t{Dir} = '../' . $$s_ref{E_DIR}; $t{Header} = $$s_ref{NAME1}; # Open the directory opendir(BIN,$t{Dir}) or die "Can't open $t{Dir}.\n"; # Deal with files one by one while (defined ($t{file} = readdir BIN) ) { next if $t{file} =~ /^\.\.?$/; if ( $t{file} =~ /^$t{Header}(.*)\.xls$/ ) { push(@{ $$s_ref{files}{$t{Header}} },$t{file}); } } closedir(BIN); return($s_ref); } __DATA__ NAME ENQ INV ORDER PACKING PRE-INV PRO-INV QTN SHIPPING C E_DIR T_DIR SQL==>WORK 2005==>txt

戻る