in reply to Re: Re: Hash of directories?
in thread Hash of directories?
You're already building a hash of the directory structure you said, so along that vein how about this (untested piece of code)
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.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;
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
|
|---|