copy directory structure without files

Discussion in 'Perl Misc' started by ioneabu@yahoo.com, Feb 8, 2005.

  1. Guest

    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
    , Feb 8, 2005
    #1
    1. Advertising

  2. phaylon Guest

    ioneabu wrote:

    > 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

    --
    http://www.dunkelheit.at/

    The first rule of project mayhem is: you do not ask questions.
    -- Fight Club
    phaylon, Feb 8, 2005
    #2
    1. Advertising

  3. Guest

    phaylon wrote:
    > ioneabu wrote:
    >
    > > 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.


    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;

    >
    > hth,
    > phay
    >
    > --
    > http://www.dunkelheit.at/
    >
    > The first rule of project mayhem is: you do not ask questions.
    > -- Fight Club
    , Feb 8, 2005
    #3
  4. phaylon Guest

    ioneabu wrote:

    > 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

    --
    http://www.dunkelheit.at/
    That is not dead, which can eternal lie,
    and with strange aeons even death may die.
    -- H.P. Lovecraft
    phaylon, Feb 8, 2005
    #4
  5. phaylon <> wrote:
    > ioneabu wrote:


    >> 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.


    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

    --
    Darren Dunham
    Senior Technical Consultant TAOS http://www.taos.com/
    Got some Dr Pepper? San Francisco, CA bay area
    < This line left intentionally blank to confuse you. >
    Darren Dunham, Feb 15, 2005
    #5
  6. 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

    --
    perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
    ..32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
    Martin Kissner, Feb 16, 2005
    #6
  7. 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

    --
    perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
    ..32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
    Martin Kissner, Feb 16, 2005
    #7
  8. 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

    --
    perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
    ..32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
    Martin Kissner, Feb 16, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Blair
    Replies:
    4
    Views:
    1,082
    John Saunders
    Jan 12, 2005
  2. Alex
    Replies:
    2
    Views:
    1,218
  3. Leo Nunez
    Replies:
    3
    Views:
    1,204
    Neil Kurzman
    Feb 9, 2005
  4. Replies:
    26
    Views:
    2,107
    Roland Pibinger
    Sep 1, 2006
  5. Jeremy Conlin

    Copy directory tree without copying files

    Jeremy Conlin, Sep 23, 2009, in forum: Python
    Replies:
    9
    Views:
    2,503
    Jeremy Conlin
    Sep 23, 2009
Loading...

Share This Page