" d t. I \ H e, k" T4 @ 1 T& Y1 S' `/ R4 ^% r a( O# E) h+ O f4 \3 H( @: D0 e
def dump(st): 5 E( P% _$ \+ \1 S: G& u J5 t! \& m1 _1 W
mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = st & T5 `/ j: P, t5 a( s 9 |$ O9 L3 K* p$ c4 Z! A0 x' a gprint "- size:", size, "bytes"% g+ B% d9 T2 x, G. I0 T& H
" C! q* |- i2 dprint "- owner:", uid, gid( P+ _8 s, Z7 O/ o/ v F# Q3 S+ n2 Y
) [% ^5 A. y7 Q ]- _; E# R; b, L9 K
print "- created:", time.ctime(ctime) " N: H6 U" c& c b* u8 ]4 }- c. a
print "- last accessed:", time.ctime(atime) 4 T J$ j0 f S* r 1 E* ?9 `! u% \/ `print "- last modified:", time.ctime(mtime) % z5 ?6 _0 I9 H5 t1 N( c# ? c' a# q
print "- mode:", oct(mode) ( @" d2 o+ f% V 5 K; M5 V, g8 Q. T) Mprint "- inode/dev:", ino, dev! V ?" |1 ^- B( a
& u# H5 _- P. o* z- X: B
4 ^% G: Z8 v. U" B / @* M* p' k: bprint dir(st) + P. _% f; G8 r; X 3 w; u8 a1 C, P' wprint , [# a. E+ E3 s- _7 Q* \$ d1 g6 B- E
dump(st)3 z/ O; G' Y- V4 x
4 P c) F+ @+ k; R8 J* F
# print5 e: y4 @9 t+ e' C
2 j7 B x2 j$ }( V - N7 `4 Z- m' L o( H' d; l# u: B( m+ m& a' ~, R
fp = open(file)4 H8 \. R7 _- a, j: e! l
/ j# j: W' S5 m" y, y# A! Pst = os.fstat(fp.fileno()) , |: B0 n7 ]8 ]$ } % n4 e$ H0 g, V) }, N1 y' qprint "fstat", file- w8 ?3 {& u4 C( i' I$ }
. w+ b L7 ], |- U. A: a k4 k
dump(st) : F, m/ {$ h ~ 8 u9 V4 F6 O8 R/ C6 P& \: L3 k 7 `3 X5 i! A8 Q* V A6 r- M! p: a9 c6 Q2 v
remark: os.stat(path/file)返回文件的对应属性值st_mode (protection bits), st_ino (inode number), st_dev (device), st_nlink (number of hard links), st_uid (user id of owner), st_gid (group id of owner), st_size (size of file, in bytes), st_atime (time of most recent access), st_mtime (time of most recent content modification), st_ctime (platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows): . c% t* r3 D5 |& v5 t) \6 X! O " V* I( K: R' W- cos.fstat(path/file) : q% k' w' M) ?3 _7 s 3 _2 i B' o- IReturn status for file descriptor fd, like stat(). 作者: darker50 时间: 2012-7-10 16:38
可以放进文档当成附件下载的!作者: Seawind2012 时间: 2012-7-10 19:00