copy directory structure without files

I

ioneabu

This will copy whole directory structure with files (Thanks Sherm! -
from old post).

#!/usr/bin/perl

use strict;
use warnings;

use File::NCopy;

my $copier = new File::NCopy(recursive=>1, force_write=>1);
$copier->copy('dir1', 'dir2'); #important: dir2 must exist first

QUESTION: What if I want to copy the directory structure but not the
files?

I am putting together a photo album and will be using ImageMagick to
convert from huge size to 640x480 but I want to copy my original photo
directory structure first and then use ImageMagick to convert the
pictures and copy them to the new directories.

Thanks!

wana
 
P

phaylon

ioneabu said:
use File::NCopy;
...
QUESTION: What if I want to copy the directory structure but not the
files?

In the docs I could'nt find (am I the only one getting »bad request« at
search.cpan.org?) any option which could do this. I don't know what the
original Thread was, so just the question: Why aren't you making this with
your shell? 'find', 'xargs' and 'mkdir' should be enough. It shouldn't
also be a great problem to do this in Perl with File::Find.

hth,
phay
 
I

ioneabu

phaylon said:
In the docs I could'nt find (am I the only one getting »bad request« at
search.cpan.org?) any option which could do this. I don't know what the
original Thread was, so just the question: Why aren't you making this with
your shell? 'find', 'xargs' and 'mkdir' should be enough. It shouldn't
also be a great problem to do this in Perl with File::Find.

That's true. I just thought it would make a great option to
File::NCopy and I was hoping there was a trivial way to do it. I'll
get to work on doing it that way. Like this?

use strict;
use warnings;
use File::Find;
use File::path;

my ($source, $target) = @ARGV;
my @paths;
find sub {push @paths, "$target/$File::Find::name" if -d and not
/^\.{1,2}/;}, $source;
mkpath "$_" for @paths;
 
P

phaylon

ioneabu said:
Like this?

Yep, that imho looks good. The only thing is your regular expression:

/^\.{1,2}/

which matches everything that starts with one or two points. So you
would skip the directory /test/...foo/ for example. I don't know if you
want that, but if you make a

/^\.{1,2}$/

out of that, it should work as (I) expected.

bye,
phaylon
 
D

Darren Dunham

phaylon said:
ioneabu wrote:
In the docs I could'nt find (am I the only one getting »bad request« at
search.cpan.org?) any option which could do this. I don't know what the
original Thread was, so just the question: Why aren't you making this with
your shell? 'find', 'xargs' and 'mkdir' should be enough. It shouldn't
also be a great problem to do this in Perl with File::Find.

or for other non-perl solutions, I like this, especially if you have to
do it more than once in the same location.

rsync -a --include "*/" --exclude "*" source/ target
 
M

Martin Kissner

Darren Dunham wrote :
or for other non-perl solutions, I like this, especially if you have to
do it more than once in the same location.

rsync -a --include "*/" --exclude "*" source/ target

To do the same thing, but creating a file that can be reused:

To create the DIRLIST-file:
find . -type d -print0 | cpio -o -O > DIRLIST
To extract it:
cpio -i < DIRLIST

HTH
Martin
 
M

Martin Kissner

Darren Dunham wrote :
or for other non-perl solutions, I like this, especially if you have to
do it more than once in the same location.

rsync -a --include "*/" --exclude "*" source/ target

To do the same thing, but creating a file that can be reused:

To create the DIRLIST-file:
find . -type d -print0 | cpio -o -O DIRLIST
To extract it:
cpio -i < DIRLIST

HTH
Martin
 
M

Martin Kissner

Darren Dunham wrote :
or for other non-perl solutions, I like this, especially if you have to
do it more than once in the same location.

rsync -a --include "*/" --exclude "*" source/ target

To do the same thing, but creating a file that can be reused:

To create the DIRLIST-file:
find . -type d -print0 | cpio -o -O DIRLIST
To extract it:
cpio -i < DIRLIST

HTH
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top