Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: copy script

by kiruthika.bkite (Scribe)
on Mar 25, 2010 at 11:29 UTC ( #830832=note: print w/ replies, xml ) Need Help??

in reply to copy script

use File::Find; my $command="cp"; my $target="/home/kiruthika/Technical/NEW/"; #Here mention your direct +ory path to where you need to copy the files. my $str; find(\&wanted,(".","..",)); sub wanted() { if(/.*\.txt/)#find the .txt files and copy those into another loca +tion. { $str=$command." ".$_." " .$target; system("$str"); $str=" "; } }

find() function will call the wanted function for each files in the current directory and as well in the parent directory of the current directory.

In the wanted function I have checked whether the file is .txt file or not.
If it is .txt file then I have copied that file into the target directory.

In find() function ,in the second argument you mention the directories to be searched.

Comment on Re: copy script
Download Code
Re^2: copy script
by marto (Bishop) on Mar 25, 2010 at 11:56 UTC

    So you are assuming the cp command is available, calling it via system, you're also assuming that the copy has worked and not bothered to check for errors?. Why not use File::Copy (it's core and portable) and actually check that no error was returned?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://830832]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2015-03-29 05:20 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (630 votes), past polls