C
cca.johnson
I want to be able to rename a file and prepend the file's modification
date at the front of the file. For example:
with a file named testme.txt and a modification date of April 1, 2006,
I want the renamed file to be named 20060401-testme.txt
What I can do is get the modification date using ctime, but it I can't
figure out how to format the output. I am able to format the date the
way I like using strftime. Here is some sample code which shows the
output I do and do not want:
#!/usr/bin/perl -w
use strict ;
use warnings ;
use POSIX qw(strftime);
# print today's date YYYYMMDD:
my $now_time = strftime "%Y%m%d", localtime;
print "I want it formatted this way:\n$now_time\n";
# print the modified date of file:
use File::stat;
use Time::localtime;
my $file = "testme.txt";
my $timestamp = ctime(stat($file)->mtime);
print "...but not this way:\n $timestamp\n";
Any assistance would be appreciated,
date at the front of the file. For example:
with a file named testme.txt and a modification date of April 1, 2006,
I want the renamed file to be named 20060401-testme.txt
What I can do is get the modification date using ctime, but it I can't
figure out how to format the output. I am able to format the date the
way I like using strftime. Here is some sample code which shows the
output I do and do not want:
#!/usr/bin/perl -w
use strict ;
use warnings ;
use POSIX qw(strftime);
# print today's date YYYYMMDD:
my $now_time = strftime "%Y%m%d", localtime;
print "I want it formatted this way:\n$now_time\n";
# print the modified date of file:
use File::stat;
use Time::localtime;
my $file = "testme.txt";
my $timestamp = ctime(stat($file)->mtime);
print "...but not this way:\n $timestamp\n";
Any assistance would be appreciated,