Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w use strict; use File::Copy; my $cnt; my $infile = "C:\\dir1\\file.chr"; my ( $yr, $mo, $dy ) = (localtime)[5,4,3]; my $outfile = sprintf( "C:\\radtrans\\%04d%02d%02d.txt",$yr+1900,$mo+1 +,$dy ); my $staticdir = "C:\\dir1\\dir2\\"; my %index; my $filename; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; $cnt++; while (<IN>) { chomp; my @fields = split /\|/; my @newfile = $fields[0]; for (@newfile) { if ($index{$_}) { $filename = $_. $index{$_}; $index{$_}++; } else { $filename = $_; $index{$_} = 'a'; } } my $path_str = $fields[19]; do { warn "Empty field 19"; next } unless $path_str; my @path = split /\\/, $path_str; my $dir = join "\\", @path[ 0, 1, 2, 3, 4, 5, 6 ]; $filename =~ s/$/.rtf/; my $out = join ('|', @fields[0..18]) . "@@" . $staticdir . $filena +me; print OUT "$out\n"; process_dir($dir,$filename); } close IN; sub process_dir { my ($dir, $filename) = @_; do { warn "$dir does not exist!\n"; return } unless -e $dir; opendir DIR, $dir or do { warn "Could not open $dir $!\n" ; return }; while ( my $file = readdir DIR ) { print "dir: $dir file:$file Newfile:$filename\n"; #before the next unless statements. next unless -f "$dir\\$file"; next unless $file =~ m/\.rtf$/i; copy( "$dir\\$file", "C:\\dir1\\dir2\\$filename" ) or die "Failed to copy $file: $!\n"; } indeximageimport; } sub IndexImageImport { my $processfile = sprintf( "%04d%02d%02d.txt",$yr+1900,$mo+1,$dy ); chdir "c:\\Program Files\\Software\\dir1software\\" or die "cannot chd +ir c:\\Program Files\\Software\\dir1software\\: $!"; exec "IndexImageImport.exe /U (user) /W (password) /A Application /S f +ileApp /F C:\\RADTRANS\\$processfile"; die "indeximageimport couldn't run: $!"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Automation Script to Process file
by Plankton (Vicar) on Jun 03, 2004 at 20:35 UTC | |
|
Re: Automation Script to Process file
by Joost (Canon) on Jun 03, 2004 at 20:32 UTC |