smanicka has asked for the wisdom of the Perl Monks concerning the following question:
here is my script for performing actions on files in a folder based on their names.I have a few questions reg that.most of the actions are performed on a pdf copy of the file but just one chooses the ascii version.I need a method to clean up the files in the folder after all the actions are performed. There may be multiple actions for each file.
Also I am trying to figure out how to make it run forever in the background and give logging functionality ie i need the date time that each action was performed.The server is a windows server.#!usr/bin/perl -w use DBI; use File::Copy; @files=<H:/what_to_do/*>; foreach my $file (@files){ my @arr=split(/\//,$file); print "\n"; my @field=split(/%/,$arr[2]); print $arr[2]; my $length_arr=length($arr[2]); my $fname=substr($arr[2],0,($length_arr-4)); print "\n$fname"; my $sysacc=$field[0]; my $rid=$field[2]; my $jid=$field[1]; my $oldloc=$file; my $key=$sysacc."%".$jid."%".$rid; print "\n\nLOOKING UP KEY: $key \n"; $dbh =DBI->connect("dbi:Oracle:host=abc123;sid=test","scott","tiger!") + or die "cannot connect to oracle"; $dbh->{AutoCommit}=0; my $query= "select * from lookup where name_key=\'$key\'"; my $sth=$dbh->prepare($query) or die "prepare failed"; $sth->execute() or die "execute failed"; my $status=0; while(@row=$sth->fetchrow_array()){ $status=1; $print=$row[1]; $not_print=$row[2]; $action1=$row[3]; $action2=$row[4]; $action3=$row[5]; $action4=$row[6]; } $sth->finish(); $dbh->disconnect(); if($status==0){ print "\nFile moved to print\n"; } else{ if( $action4 eq "yes"){ $newloc="h:/HOT/TO BE PROCESSED/$arr[2]"; move($oldloc,$newloc)or die "fail to move"; } my $asciiloc="h:/Ascii/$fname.txt"; print "\n\n$asciiloc\n"; if ($action2 eq "yes"){ $newloc="h:/HOT/cold/$arr[2]"; move($asciiloc,$newloc)or die "fail to move"; } elsif ($action1 eq "yes"){ $newloc="h:/HOT/action2/$arr[2]"; copy($oldloc,$newloc)or die "fail to move"; } if ($action3 eq "yes"){ $newloc="h:/HOT/action3/$arr[2]"; copy($oldloc,$newloc)or die "fail to move"; } if( $not_print eq "yes"){ $newloc="h:/HOT/not_print/$arr[2]"; move($oldloc,$newloc)or die "fail to move"; print "\n+---------------------+\n Moved file to Not print folder \n+- +--------------------+\n"; } if( $print eq "yes"){ $newloc="h:/HOT/print/$arr[2]"; move($oldloc,$newloc)or die "fail to move"; print "\n+---------------------+\n Moved file to print \n+------------ +---------+\n"; } } }
Any help would be appreciated.Thank you monks -Smanicka
UPDATE: I found out how to get the loacl time : http://perl.about.com/od/perltutorials/a/perllocaltime_2.htm
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: actions lookup ,need help automating
by frieduck (Hermit) on Jan 08, 2009 at 19:23 UTC |