in reply to Re^2: Manage Directory Structure
in thread Manage Directory Structure
How about breaking the problem down to three separate procedures:
File::Find will be good for the first step, though you might want to consider just using the available unix/linux tools:
find /path/of_interest -type d | sort > /path/for_log_info/dirlist.y +ymmdd
Using "diff" on two consecutive "dirlist" files will reveal the addition or removal of directories.
For step 2, I would do something like:
With that done, running the basic "diff" command on two consecutive file listings for a given directory (assuming that the directory existed on both days) will tell you which files changed, which were added, and which were removed. Just figure out what you want to do with the output from "diff".open( DLIST, "<", $dirlist ); while ( my $dir = <DLIST>) { chomp $dir; opendir D, $dir or do { warn "opendir failed on $dir: $!\n"; next; }; ( my $file_list_name = $dir ) =~ tr{/}{%}; open( FLIST, ">", "$log_path/$file_list_name.$today" ) or die "cannot write to $log_path/$file_list_name.$today: $!\n +"; for my $file ( sort grep { !-d "$dir/$_" } readdir( D )) { # check for symlink vs. datafile # gather other stat info as needed, # print a nicely formatted line to FLIST } close FLIST; closedir D; } close DLIST;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Manage Directory Structure
by boardryder (Novice) on Jul 05, 2009 at 04:34 UTC | |
by graff (Chancellor) on Jul 05, 2009 at 14:38 UTC | |
by boardryder (Novice) on Jul 26, 2009 at 05:18 UTC |