Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: Check if file exists in multiple directories

by 2teez (Vicar)
on May 21, 2015 at 18:23 UTC ( #1127375=note: print w/replies, xml ) Need Help??

in reply to Re^2: Check if file exists in multiple directories
in thread Check if file exists in multiple directories

Hi Bama_Perl,

What I don't understand is do you want the file "outFile" moved or copied? Because, if you move it to say the first directory that has '*.txt', what happens to another say "fourth" directory that also has '*.txt'?

Secondly, I think you should be using a perl core module like File::Copy to achieve your aim instead of using mv command in system like you are doing.

Third, you may use File::Find module to do the searching of directories for you.
Lastly, use three arguments open function and a lexical scoped file-handler (this is an old wisdom that still holds true in a way today)

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
  • Comment on Re^3: Check if file exists in multiple directories

Replies are listed 'Best First'.
Re^4: Check if file exists in multiple directories
by Bama_Perl (Acolyte) on May 21, 2015 at 18:29 UTC
    Hi 2teez, I want to copy the $outFile to a new directory. I don't want to move it to a directory that has *.txt. In other words, as I loop through each directory, if that directory has a *.txt file, then I want to move the $outfile within that directory to a new directory. If that directory does not have a *.txt file, then nothing will be moved to a new directory. I'll look into File::Copy to see how that can help me. Thanks!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2021-04-14 18:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found