開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語:Perl
『初めてのPerl 第6版』(Randal L. Schwartz, Tom Phoenix, brian d foy 共著、近藤 嘉雪 訳、オライリー・ジャパン、2012年、ISBN978-4-87311-567-2) の17章(上級テクニック)、17.6(練習問題)3を解いてみる。
その他参考書籍
3.
コード(BBEdit)
sample.pl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use 5.016;
binmode STDOUT, ':utf8';
binmode STDIN, ':utf8';
for my $file (glob "*"){
my($atime, $mtime) = map{
my($day, $mon, $year) = (localtime $_)[3, 4, 5];
$mon += 1;
$year += 1900;
sprintf "%4d-%02d-%02d", $year, $mon, $day;
} (stat $file)[8, 9];
printf "%-25s%20s%20s\n", $file, $atime, $mtime;
}
入出力結果(Terminal)
$ ./sample.pl __pycache__ 2012-12-29 2013-01-17 barney 2012-12-20 2001-06-10 betty 2012-12-20 2001-06-10 coconet.dat 2012-10-24 2011-10-24 date.txt 2012-11-10 2012-04-24 fred 2012-12-20 2001-06-10 gilligan.info 2012-12-20 2012-10-27 ginger.info 2012-12-20 2012-10-27 hello_world.pl 2012-12-19 2012-12-19 link_test 2013-01-16 2012-03-18 ln.txt 2013-01-01 2013-01-01 ln1.txt 2013-01-01 2013-01-01 log 2012-12-20 2012-10-26 log_file.txt 2012-10-27 2011-07-28 lovey.info 2012-12-20 2012-10-27 ls.err 2013-01-13 2013-01-13 ls.out 2013-01-13 2013-01-13 maryann.info 2012-12-20 2012-10-27 monkeyman.info 2012-12-20 2012-10-27 numbers 2012-12-20 2001-06-10 Oogaboogoo 2012-12-29 2012-08-04 perl_kamimura_blog 2012-12-20 2012-12-20 perl_kamimura_blog.html 2013-01-18 2013-01-17 perl_program1 2012-12-20 2012-03-19 professor.info 2012-12-20 2012-10-27 result 2012-12-20 2012-07-18 sample 2013-01-16 2012-06-26 sample.pl 2013-01-18 2013-01-18 sample.pl.bak 2012-12-19 2012-12-19 sample.py 2013-01-18 2013-01-17 sample_folder 2013-01-16 2012-06-25 sample_text 2013-01-16 2001-06-10 skipper.info 2012-12-20 2012-10-27 some_file 2012-12-24 2012-12-24 some_folder 2013-01-16 2013-01-02 sortable_hash 2012-12-20 2001-06-10 standings.db 2012-12-20 2012-11-07 test.out 2012-12-20 2012-12-15 test.txt 2013-01-16 2012-03-18 test_folder 2012-12-29 2012-04-30 test_link 2013-01-16 2012-03-18 thurston.info 2012-12-20 2012-10-27 tmp.txt 2012-12-14 2012-11-29 tmp_folder 2012-12-29 2012-09-26 total_bytes.dat 2012-10-24 2012-10-24 untitled text 2.txt 2012-11-05 2012-11-05 $
pythonの場合。
sample.py
コード(BBEdit)
#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-
import glob, os, datetime
for file in glob.glob("*"):
atime, mtime = map(lambda x: x.strftime("%Y-%m-%d"),
map(lambda x: datetime.datetime.fromtimestamp(x), os.stat(file)[7:9]))
print("{0:25s}{1:20s}{2:20s}".format(file, atime, mtime))
入出力結果(Terminal)
$ ./sample.py __pycache__ 2012-12-29 2013-01-18 barney 2012-12-20 2001-06-10 betty 2012-12-20 2001-06-10 coconet.dat 2012-10-24 2011-10-24 date.txt 2012-11-10 2012-04-24 fred 2012-12-20 2001-06-10 gilligan.info 2012-12-20 2012-10-27 ginger.info 2012-12-20 2012-10-27 hello_world.pl 2012-12-19 2012-12-19 link_test 2013-01-16 2012-03-18 ln.txt 2013-01-01 2013-01-01 ln1.txt 2013-01-01 2013-01-01 log 2012-12-20 2012-10-26 log_file.txt 2012-10-27 2011-07-28 lovey.info 2012-12-20 2012-10-27 ls.err 2013-01-13 2013-01-13 ls.out 2013-01-13 2013-01-13 maryann.info 2012-12-20 2012-10-27 monkeyman.info 2012-12-20 2012-10-27 numbers 2012-12-20 2001-06-10 Oogaboogoo 2012-12-29 2012-08-04 perl_kamimura_blog 2012-12-20 2012-12-20 perl_kamimura_blog.html 2013-01-18 2013-01-18 perl_program1 2012-12-20 2012-03-19 professor.info 2012-12-20 2012-10-27 result 2012-12-20 2012-07-18 sample 2013-01-16 2012-06-26 sample.pl 2013-01-18 2013-01-18 sample.pl.bak 2012-12-19 2012-12-19 sample.py 2013-01-18 2013-01-18 sample_folder 2013-01-16 2012-06-25 sample_text 2013-01-16 2001-06-10 skipper.info 2012-12-20 2012-10-27 some_file 2012-12-24 2012-12-24 some_folder 2013-01-16 2013-01-02 sortable_hash 2012-12-20 2001-06-10 standings.db 2012-12-20 2012-11-07 test.out 2012-12-20 2012-12-15 test.txt 2013-01-16 2012-03-18 test_folder 2012-12-29 2012-04-30 test_link 2013-01-16 2012-03-18 thurston.info 2012-12-20 2012-10-27 tmp.txt 2012-12-14 2012-11-29 tmp_folder 2012-12-29 2012-09-26 total_bytes.dat 2012-10-24 2012-10-24 untitled text 2.txt 2012-11-05 2012-11-05
0 コメント:
コメントを投稿