|
Re: 搭建自己的网上相册
修改照片文件名,从 数码相机的文件名 ===> 日期-天数-顺序号这样的格式。
下载perl, 然后在相片目录下执行下面脚本。
#!/usr/bin/perl
#===============================================================================
#
# FILE: baby_pic.pl
#
# USAGE: ./baby_pic.pl
#
# DESCRIPTION: Baby picture file name processing.
# From SV4000xx ==>
# To YYYY-MM-DD_n-xx
# n = 出生天数,2006-08-13 = 1
# 2006-08-15 = 3
# 2006-09-05 = 51
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR:
# COMPANY: none
# VERSION: 1.0
# CREATED: 2007-1-2 17:27:10 中国标准时间
# REVISION: ---
#===============================================================================
use strict;
use warnings;
use HTTP::Date;
my $born_date = "2006-08-13 12:50";
foreach my $file (<*.jpg>)
{
my $mtime = (stat($file))[9]; # modify time
my $days = int(($mtime - str2time($born_date))/(24*3600)) + 1;
print "file=$file, mtime=$mtime\n";
my ($year,$mon,$mday) = (localtime($mtime))[5,4,3];
my $new_file_name = sprintf("%04d-%02d-%02d_%d-%s", $year+1900, $mon+1, $mday, $days, substr($file, 6));
print "rename $file to $new_file_name\n";
rename $file,$new_file_name;
}
如果比较多人感兴趣,可以做的更方便点。:) |
|