Hello,
I wrote this posting twice, but it was rejected by the listserv, because it had too many lines. I deleted many empty lines to make it shorter.
--------
Hello Christopher, Hello All,
Thank you for your comments.
Following your suggestion, I used Perl to write three laborious scripts, to achieve what I needed to do. First, this one, to get the file path of all the folder structure, and their size and modified date, and I ran this script for two folders that I had to compare:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use File::Find;
@ARGV = ("/Users/me/Documents/myFolder/");
my $startfolder = shift;
my @files;
find( \&macfind, $startfolder );
my $res = "";
for (@files) {
if (-d $_) {
$_ .= "/";
}
my $mod_date = `/usr/bin/GetFileInfo -m "$_"`;
chomp $mod_date;
my $sz = -s $_;
$res .= $_ . "\t" . $mod_date . "\t" . $sz . "\n";
}
print $res;
sub macfind {
my $file = $File::Find::name;
push( @files, $file ) unless $file =~ /\/\.[^\/]*$/;
}
Second, I used the following script to make a list of files for which I had to change the modified date:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
my $source_list = "/Users/me/Desktop/sourcefile_list.txt";
my %source_list;
open (IN, "<:utf8", $source_list) || die "Couldn't open file $source_list: $!";
while (<IN>) {
chomp;
s/^\/Volumes\/Extra_1\///;
my ($filepath, $rest) = /^([^\t]+)\t(.+)/;
$source_list{$filepath} = $rest;
}
close (IN);
my $dest_list = "/Users/me/Desktop/destfile_list.txt";
my %dest_list;
open (IN, "<:utf8", $dest_list) || die "Couldn't open file $dest_list: $!";
while (<IN>) {
chomp;
s/^\/Users\/me\/Documents\///;
my ($filepath, $rest) = /^([^\t]+)\t(.+)/;
$dest_list{$filepath} = $rest;
}
close (IN);
my $res;
foreach my $i (keys %source_list) {
if (exists $dest_list{$i}) {
my ($source_mtime, $source_sz) = split (/\t/, $source_list{$i});
my ($dest_mtime, $dest_sz) = split (/\t/, $dest_list{$i});
if ($source_sz == $dest_sz && $source_mtime ne $dest_mtime) {
$res .= "/Users/me/Documents/" . $i . "\t" . $source_mtime . "\n";
}
if ($i =~ /\/$/ && $source_sz ne $dest_sz && $source_mtime ne $dest_mtime) {
$res .= "/Users/me/Documents/" . $i . "\t" . $source_mtime . "\n";
}
}
}
binmode (STDOUT, ":utf8");
print $res;
Finally, I wrote the third script with which I corrected the modified time of the list created:
#!/usr/bin/perl
use strict;
use warnings;
@ARGV = ("/Users/me/Desktop/folder_mod_date_to_change_list.txt");
my $list_file = shift;
open (IN, "<:utf8", $list_file) || die "Couldn't open the list file $list_file: $!";
my @list_lines = <IN>;
close ($list_file);
my $error_log;
my $res_log;
for (@list_lines) {
chomp;
my ($file_path, $mod_date) = split ("\t", $_);
if (! -e $file_path) {
$error_log .= "Error: the file doesn't exist: $file_path!\n";
}
else {
my $result = `/usr/bin/SetFile -m "$mod_date" "$file_path"`;
if (! $result) {
$res_log .= "Could correct the modified date of the file $file_path to $mod_date.\n";
}
else {
$error_log .= "Error: the modified time could not set to the file $file_path: Error number: $result\n";
}
}
}
binmode (STDOUT, ":utf8");
if ($error_log) {
print "Errors:\n";
print $error_log, "\n";
}
if ($res_log) {
print "Result:\n", $res_log;
}
------
I spent long time to do this, but finally, I am rather satisfied with the result.
I used "GetFileInfo" and "SetFile" -- which seem very slow, but they are useful because are rather easy to understand and to use.
Thank you again for your help.
Best regard,
Nobumi Iyanaga
Tokyo,
Japan
|