Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Problem with mapping windows shares and File::Find

by romandas (Pilgrim)
on Mar 11, 2008 at 15:19 UTC ( [id://673528]=perlquestion: print w/replies, xml ) Need Help??

romandas has asked for the wisdom of the Perl Monks concerning the following question:

Trying to figure out how to search through files on several Windows machines. If I leave out the 'find()' line, the program completes fine, mapping and unmapping the c$ share with no issues (success messages print to the terminal).
However, with the 'find()' line included, the files from the first machine will list correctly, but the rest of the machines do not, nor do I get successful messages regarding mapping the drives. What gives?

I realize that this could likely be done faster by trying to parallelize the searches to run on multiple machines at once or by getting the job to run on the remote computer, but without using Scheduled Tasks, I am not sure how to do that.

#!/perl/bin/perl use warnings; use strict; use File::Find; foreach my $computer (<>) { chomp($computer); print($computer, "\n"); system("net", "use", "z:", '\\\\' . $computer . '\\' . 'c$'); find(\&wanted, ('z:')); system("net", "use", "z:", "/DELETE"); } sub wanted { if ((-f $File::Find::name) && ($File::Find::name =~ m/log$/i)) { print($File::Find::name); if (open(FILE, $File::Find::name)) { print("\topened\n"); close(FILE); } else { warn("Cannot open $File::Find::name: $!\n"); print("\tfailed\n"); } } }

Replies are listed 'Best First'.
Re: Problem with mapping windows shares and File::Find
by Corion (Patriarch) on Mar 11, 2008 at 15:31 UTC

    I think you don't need to map/unmap the remote paths and can just use File::Find with the UNC directly:

    find(\&wanted, "\\\\$computer\\c\$");

    The error you're getting is likely due to your usage of a bare z: instead of explicitly specifying the root directory z:\.

      I don't think that is it (but I am testing it as we 'speak') because I had z:\ in there previously, but have forgotten at this point why I took it out.

      Why would it (find()) work the first time through, but not the second?

      Update: You were right, both about the z:\ and about the UNC paths. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://673528]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-20 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found