Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Hash of directories?

by phathead22 (Novice)
on Jan 27, 2001 at 00:06 UTC ( [id://54626]=note: print w/replies, xml ) Need Help??


in reply to Re: Hash of directories?
in thread Hash of directories?

This is an NT based system running Active State Perl; I'll admit that
it was a pain getting some of the modules/libraries going (there is a recent
question RE the same:) I am not compressing any data, or even tar'ring. I just want to copy unique files
from source to target. Seems to me that the Rubbish Lister was intended for this!
Thx PH

Replies are listed 'Best First'.
Re: Re: Re: Hash of directories?
by jynx (Priest) on Jan 27, 2001 at 03:07 UTC
    ok,

    You're already building a hash of the directory structure you said, so along that vein how about this (untested piece of code)

    use File::Find; # these should work on any platform : ) use File::Copy; # i'm naming your target directory hash %files, # and the directories are $target and $source (strings) sub checker { return if exists %files, $_; copy "$target$_", $File::Find::name; } find {wanted => \&checker}, $source;
    This is the first code that pops to mind. It doesn't handle directories inside of directories well at all, but if you take a look at the File utilities you should be able to get a good feel for what it's lacking. Also, for testing if a file is the same as another, you could use File::stat which would be much more specific than just names of files. And finally, for creating the target hash structure to begin with you might want to use File::Find to help you traverse correctly down the tree. That way you don't get any infinite directories or some such nasty beasts.

    find and copy do all of the grunt work here, you only need to modify the code to deal with how you laid out your hashes. It is untested, but it should work for directories that don't have any subdirectories in them.

    Hope That Helps,
    jynx

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://54626]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-16 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found