CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
unable to move file using system ()

 



ajitbhaskaran
Novice

Jan 21, 2008, 3:22 AM

Post #1 of 4 (764 views)
unable to move file using system () Can't Post

hi,

this is the script i am using to identify log files getting generated in a folder and if found shifted to a folder WIP( work in progress) , the script is working fine but the file is not getting moved to the new directory :



#!/usr/bin/perl

use strict;
use warnings;

my $list;
system "ls *.log >> list.out" ;
my @check_files=("list.out");
for my $check_file (@check_files)
{
if ( -f "$check_file" )
{
open(LOG_FILE,"$check_file") || die "Cannot open $check_file";
while( my $line = <LOG_FILE> )
{
my $thread_line=$line;
print $thread_line;
my $from = "'$thread_line'";
my $to = " ../WIP/'$thread_line'";
my $action= " mv $from $to ";
#rename("$from", "$to");
system($action);

}
close(LOG_FILE);
}
}
system " rm -f list.out ";

~
after execution it gives the error:

ram.log
mv: ram.log
: cannot access: No such file or directory


can anyone help please:


winfinit
User

Jan 28, 2008, 6:54 PM

Post #2 of 4 (743 views)
Re: [ajitbhaskaran] unable to move file using system () [In reply to] Can't Post

umm not sure what you are trying to do here, basically if i understand correctly you are trying to see if a particular directory contains files .log, if it does, then you want to take those files and move them, if that is so then you can do this

#!/usr/bin/perl

my @array;
@array = `ls -1 *.log`;
foreach(@array)
{
chomp($_);
`mv $_ ../AnotherFolder/`;
}

this script will have to be executed from directory where your .log files are

result:
winfinit:test winfinit$ ls
1.log 2.log 3.log 4.log test.pl
winfinit:test winfinit$ perl test.pl
winfinit:test winfinit$ ls
test.pl
winfinit:test winfinit$ cd ../AnotherFolder/
winfinit:AnotherFolder winfinit$ ls
1.log 2.log 3.log 4.log
winfinit:AnotherFolder winfinit$


KevinR
Veteran


Jan 29, 2008, 2:16 AM

Post #3 of 4 (734 views)
Re: [ajitbhaskaran] unable to move file using system () [In reply to] Can't Post

ajitbhaskaran,

You have posted several threads recently and not responded to any of the replies you have been given. How does anyone here know if you are reading the replies or if they are helping you?
-------------------------------------------------


ajitbhaskaran
Novice

Jan 29, 2008, 2:23 AM

Post #4 of 4 (729 views)
Re: [KevinR] unable to move file using system () [In reply to] Can't Post

hi,

sorry for not replying, i know its not the right thing to do, but was in a lot of pressure with my assignments, will be careful from now. thanks for the support.

regards

ajit bhaskaran

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives