Skip to content

Instantly share code, notes, and snippets.

@d0k
Created November 26, 2009 14:14
Show Gist options
  • Save d0k/243479 to your computer and use it in GitHub Desktop.
Save d0k/243479 to your computer and use it in GitHub Desktop.
apply file times from one file to another
#!/usr/bin/perl
use warnings;
use strict;
use File::stat;
use File::Basename;
if (@ARGV == 0) {
print {*STDERR} "Usage: $0 infile outfile\n";
print {*STDERR} "Usage: $0 indir outdir\n";
exit 1;
}
sub copytime {
my ($in, $out) = @_;
my $stat = stat $in;
utime $stat->atime, $stat->mtime, $out;
}
if (-d $ARGV[0]) {
for (glob "$ARGV[0]/*") {
my $newpath = basename $_;
print $newpath, "\n";
copytime $_, "$ARGV[1]/$newpath";
}
} else {
copytime $ARGV[0], $ARGV[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment