Created
November 26, 2009 14:14
-
-
Save d0k/243479 to your computer and use it in GitHub Desktop.
apply file times from one file to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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