For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2006 > Copying files in windows from one directory to the other









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Copying files in windows from one directory to the other
Kilaru Rajeev

2006-07-12, 6:57 pm

Hi,

I got some files in $BNY_DOWNLOAD which is a directory in windows. Now i
have to identify most recent one in that file and
have to move it $BNY_DATA directory it is also a directory. To identify the
most recent file I used sort command and sorted it
by using -M and and space ship operators. It is returning list of files in
that directory that are sorted by the last modification order.
I'm getting that most recently modified as the first element in the sorted
list. Now I want to move this file from this $BNY_DOWNLOAD
to $BNY_DATA directory. I'm not familiar with the windows environment that's
why please help elaborately. Waiting for your earlier responce. Please note
I'm have to use the $BNY_DATA and $BNY_DOWNLOAD while copying.

Regards,
Rajeev

Tom Phoenix

2006-07-12, 6:57 pm

On 7/12/06, kilaru rajeev <kilarurajeev@gmail.com> wrote:

> Now I want to move this file from this $BNY_DOWNLOAD
> to $BNY_DATA directory.


You may be able to simply use rename() to do what you want, but it
sounds as if you might want to use the File::Copy module, and its
move() function. Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
Timothy Johnson

2006-07-12, 6:57 pm

Probably the simplest way to do this would be to use the File::Copy
module. It's about as straightforward as you can get.

move($BNY_DOWNLOAD."\\".$filename,$BNY_DATA."\\".$filename) or
die("Couldn't copy $filename to $BNY_DATA! $!\n");


-----Original Message-----
From: kilaru rajeev [mailto:kilarurajeev@gmail.com]=20
Sent: Wednesday, July 12, 2006 10:44 AM
To: beginners@perl.org
Subject: Copying files in windows from one directory to the other

Hi,

I got some files in $BNY_DOWNLOAD which is a directory in windows. Now
i
have to identify most recent one in that file and
have to move it $BNY_DATA directory it is also a directory. To identify
the
most recent file I used sort command and sorted it
by using -M and and space ship operators. It is returning list of files
in
that directory that are sorted by the last modification order.
I'm getting that most recently modified as the first element in the
sorted
list. Now I want to move this file from this $BNY_DOWNLOAD
to $BNY_DATA directory. I'm not familiar with the windows environment
that's
why please help elaborately. Waiting for your earlier responce. Please
note
I'm have to use the $BNY_DATA and $BNY_DOWNLOAD while copying.

Regards,
Rajeev

John W. Krahn

2006-07-12, 6:57 pm

kilaru rajeev wrote:
> Hi,


Hello,

> I got some files in $BNY_DOWNLOAD which is a directory in windows. Now i
> have to identify most recent one in that file and
> have to move it $BNY_DATA directory it is also a directory. To identify the
> most recent file I used sort command and sorted it
> by using -M and and space ship operators. It is returning list of files in
> that directory that are sorted by the last modification order.
> I'm getting that most recently modified as the first element in the sorted
> list. Now I want to move this file from this $BNY_DOWNLOAD
> to $BNY_DATA directory. I'm not familiar with the windows environment
> that's why please help elaborately. Waiting for your earlier responce.
> Please note I'm have to use the $BNY_DATA and $BNY_DOWNLOAD while copying.


To move the file, something like:

rename "$BNY_DOWNLOAD/$file", "$BNY_DATA/$file" or die "Cannot move
'$BNY_DOWNLOAD/$file' $!";

If you want to *copy* the file like the Subject line says:

perldoc File::Copy


John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com