I have slight problem with my script. It does everything I need, except at the end of script it needs to move files into created directory -move ($file,"$kat/$folder_name/")-
It gives:
Cannot move "file_to_be_moved" No such file or directory
But the file and needed directory is there.
#!/usr/bin/perl
use warnings;
use strict;
use POSIX qw(strftime);
use File::Copy;
my $output_tag = strftime(".%Y%m%d%H%M", localtime);
my $failid='/home/rdd/script/konf.aa';
my $kpv = strftime(".%Y%m%d", localtime);
my $kat='/home/rdd/archive/rwa'.$kpv;
my (@files, $file, $folder_name);
if (open(FAILIDcnt, $failid)) {
while(my $input = <FAILIDcnt>) {
chomp($input);
my $output = $input;
$output =~ s/\.txt//;
$output .= $output_tag;
open(IF, '/home/rdd/'.$input) or next;
open(OF,'> /var/www/html/rwa_test/input/'.$output)
+ or die "Can't open $output: $!";
open(OF,'> /home/rdd/archive/copy/'.$output)
or die "Can't open $output: $!";
while(my $line = <IF>) {
last if $line =~ /^-{19}/;
$line =~ s/,/./g;
$line =~ s/\t/;/g;
print OF "$line";
}
close(OF);
close(IF);
system ("gzip /home/rdd/archive/copy/* ");
if (!-e $kat) {
mkdir $kat;
} else {
if (!-d $kat) {
die "$kat already exists and is not a folder";
}
}
opendir(DIR, "/home/rdd/archive/copy/")
or die "Can't Open Current Directory: $!";
@files = grep ~ m/^S.\w{2}/, readdir(DIR);
close DIR;
foreach $file(@files){
if($file =~ m/^S.(\w{2})/){
$folder_name = $1;
mkdir ("$kat/$folder_name");
move ($file,"$kat/$folder_name/")
or warn "Cannot move $file $!\n";
}
}
}
close (FAILIDcnt);
}
Br
Tann
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|