For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > copy dir structure









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author copy dir structure
frytaz@gmail.com

2006-01-10, 4:01 am

hi im a perl newbie

im trying to write shell script which will copy dir struture and create
0byte
files.
it looks like script scan given path and for example
/dir/files/jpg/first/ will be copied to /copy/first/

/dir/files/jpg/first/one.jpg 0.5mb -> /copy/first/one.jpg 0byte file
/dir/files/jpg/first/two.jpg 0.5mb -> /copy/first/two.jpg 0byte file
/dir/files/jpg/first/three.jpg 0.5mb -> /copy/first/three.jpg 0byte
file
/dir/files/jpg/first/ - > /copy/first/3-files-1.5mb-size 0byte file
/dir/files2/mp3/something/file.xxx 1mb -> /copy/something/file.xxx
0byte file
/dir/files2/mp3/something/ -> /copy/something/1-file-1mb-size 0byte
file

and only folders with files in them will be copied

please help me

usenet@DavidFilmer.com

2006-01-10, 4:01 am

frytaz@gmail.com wrote:
> im trying to write shell script which will copy dir struture and create 0byte files.
> <etc>


That's a fairly complex set of requirements to throw out in a usenet
group with no indication that you have made the slightest effort to do
anything on your own. But, lucky for you, it's Christmas, and I, for
one, am in a generous mood.

I did dummy-up some files and test this - it works. Of course, I will
illustrate this using the IO::All module (my favorite module) from
CPAN. Oh, and I can't give EVERYTHING away - this expresses filesizes
in bytes; conversion to megabytes (and the decision whether a
"megabyte" is 2**20 or 10**6) is left to the reader:

#!/usr/bin/perl
use strict; use warnings;
use IO::All;

my $sourcedir = "/tmp/test/dir";
my $copydir = "/tmp/test/copy";

foreach my $dir ( io($sourcedir) -> all_dirs(0) ) {
my $count = my $size = 0; my $subdir;
for (io($dir) -> all_files() ) {
$count++;
$size += io($_) -> size();
($subdir) = ( $_ =~ m!^.*/(.*)/! );
io( "$copydir/$subdir" ) -> mkpath();
io( "$copydir/$subdir/" . io($_) -> filename() ) -> touch();
}
io( "$copydir/$subdir/${count}_files_${size}_bytes" ) -> touch()
if $count;
}

__END__

Merry Christmas!

--
http://DavidFilmer.com

frytaz@gmail.com

2006-01-10, 4:01 am

when trying to execute this im have Setuid/gid script is writable by
world.
what it mean ?

frytaz@gmail.com

2006-01-10, 4:01 am

hmm there is no IO:All lib on my shell and im cant install, what im
should use instead of IO:All here ??

usenet@DavidFilmer.com

2006-01-10, 4:01 am

frytaz@gmail.com wrote:
> im cant install [IO::All]


Why can't you install the module?

frytaz@gmail.com

2006-01-10, 4:01 am

ok im installed it thank you very much

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com