in reply to Copy dir with space
Hi adriang,
I contend there are several issues here, least of which is the filename containing a space.
Firstly, use strict and warnings, if you did already, pls include with code example to show this. Secondly, copy, afaik is not a perl built-in (perldoc -f copy = not found).
copy is a utility function which can be found in another module similar to File::Spec, I cannot recall which this moment. So basically, opendir to copy files from, readdir, filter, read contents into filehandle, open new filehandle name in destination directory, print contents.
Untested! But, principally something like this, if the 'copy' containing module cannot be used.
use strict; use warnings; use File::Spec::Functions qw/catfile/; my $dirnameto = catfile(qq{pr book}); my $dirnamefrom = catfile(qq{pr perl_by_example}); opendir( $dhandlefrom, $dirnamefrom )or die; while (my $file=readdir($dirhandlefrom)) { next if $file =~ /\./; my $filecontents; {local $/ = undef; # slurp mode; open( my $tfh, '<', catfile( qq{$dirnamefrom $file} ) ) or die; $filecontents = <$tfh>; close $tfh; # for clarity; } open( my $filecopy, '>', catfile( qq{$dirnameto $file} )) or die; + print { $filecopy } $filecontents; close $filecopy; }
DC
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Copy dir with space
by adriang (Sexton) on Jul 10, 2014 at 10:40 UTC | |
by Anonymous Monk on Jul 10, 2014 at 14:52 UTC |