Hi bbb, welcome to the monastery.

Not sure what error you're hitting without having more information as the monks above mentioned. But thought a few small touches to your script, might get you closer to you finding the answer.

Tried to keep the bulk of your code, but did switch over to using autodie. It's not always appropriate to use, but here it lets us remove all your "or die..." statements and get down to the main code.

Removed the "$copylog" file, and just sent everything through STDERR using the warn command. Also was unsure why you had the "cp" line below the copy, but it wasn't helping. ;o)

And finally, your code would copy the file multiple times if it had more than one matching line. So here we add last after the first match, to tell Perl to leave the while loop and move on.

use strict; use warnings; use File::Find; use File::Copy; use autodie; my $log = q(C:\target\copylog.csv); my $target = q(C:\target); my $pattern = qr(SearchWord); close *STDERR; open *STDERR, '>', $log; find( sub { if (-f) { open my $file, '<', $_; while (my $line = <$file>) { if($line =~ m/$pattern/ig) { copy ($_, $target); warn "$_, $pattern\n"; last; } } close $file; } }, glob ('Z:\Linux\site') );

You may find that this still doesn't work in your environment, but if so, hopefully the error is a bit easier to suss out.

P.S. Since this is Perl and there is always more than one way to do it, you might find other CPAN options such as Path::Iterator::Rule more to your liking.

use strict; use warnings; use autodie; use Path::Tiny; use Path::Iterator::Rule; my $source = q(Z:\NEW\STUFF); my $pattern = qr(hello.*world); my $destination = q(C:\Users\loops\Desktop\stuff); close *STDERR; open *STDERR, '>', 'copylog.csv'; my $rule = Path::Iterator::Rule->new; $rule->file->line_match($pattern); my $next = $rule->iter( $source ); while ( defined( my $file = $next->() ) ) { eval { path($file)->copy($destination) }; print STDERR $@ ? "$@" : "$file, $pattern\n"; }

The only thing that may look out of place there is the eval block. This captures any failure of the copy, to let us report the result on the next line.


In reply to Re: Cannot copy files from linux shared to windows by Loops
in thread [Solved] Cannot copy files from linux shared to windows by bbb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.