in reply to [Solved] Cannot copy files from linux shared to windows

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.