3 \section{Standard Module
\module{stat
}}
7 The
\code{stat
} module defines constants and functions for interpreting the
8 results of
\code{os.stat()
} and
\code{os.lstat()
} (if they exist).
9 For complete details about the
\code{stat()
} and
\code{lstat()
} system
10 calls, consult your local man pages.
12 The
\code{stat
} module defines the following functions:
15 \begin{funcdesc
}{S_ISDIR
}{mode
}
16 Return non-zero if the mode was gotten from a directory.
19 \begin{funcdesc
}{S_ISCHR
}{mode
}
20 Return non-zero if the mode was gotten from a character special device.
23 \begin{funcdesc
}{S_ISBLK
}{mode
}
24 Return non-zero if the mode was gotten from a block special device.
27 \begin{funcdesc
}{S_ISREG
}{mode
}
28 Return non-zero if the mode was gotten from a regular file.
31 \begin{funcdesc
}{S_ISFIFO
}{mode
}
32 Return non-zero if the mode was gotten from a FIFO.
35 \begin{funcdesc
}{S_ISLNK
}{mode
}
36 Return non-zero if the mode was gotten from a symbolic link.
39 \begin{funcdesc
}{S_ISSOCK
}{mode
}
40 Return non-zero if the mode was gotten from a socket.
43 All the data items below are simply symbolic indexes into the
10-tuple
44 returned by
\code{os.stat()
} or
\code{os.lstat()
}.
46 \begin{datadesc
}{ST_MODE
}
47 Inode protection mode.
50 \begin{datadesc
}{ST_INO
}
54 \begin{datadesc
}{ST_DEV
}
55 Device inode resides on.
58 \begin{datadesc
}{ST_NLINK
}
59 Number of links to the inode.
62 \begin{datadesc
}{ST_UID
}
66 \begin{datadesc
}{ST_GID
}
67 Group id of the owner.
70 \begin{datadesc
}{ST_SIZE
}
74 \begin{datadesc
}{ST_ATIME
}
78 \begin{datadesc
}{ST_MTIME
}
79 Time of last modification.
82 \begin{datadesc
}{ST_CTIME
}
83 Time of last status change (see manual pages for details).
92 def process(dir, func):
93 '''recursively descend the directory rooted at dir, calling func for
96 for f in os.listdir(dir):
97 mode = os.stat('
%s/%s' % (dir, f))[ST_MODE]
99 # recurse into directory
100 process('
%s/%s' % (dir, f), func)
102 func('
%s/%s' % (dir, f))
104 print 'Skipping
%s/%s' % (dir, f)
107 print 'frobbed', file
109 if __name__ == '__main__': process(sys.argv
[1], f)