Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libstat.tex @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | bc02c3b09626 |
| children | 69bc7ca5cc1a |
| rev | line source |
|---|---|
| 8918 | 1 \section{\module{stat} --- |
| 10334 | 2 Interpreting \function{stat()} results} |
| 3 | |
| 8918 | 4 \declaremodule{standard}{stat} |
| 10334 | 5 \modulesynopsis{Utilities for interpreting the results of |
| 6 \function{os.stat()}, \function{os.lstat()} and \function{os.fstat()}.} | |
| 8918 | 7 \sectionauthor{Skip Montanaro}{skip@automatrix.com} |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
8716
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7908
diff
changeset
|
9 |
| 8918 | 10 The \module{stat} module defines constants and functions for |
|
10678
19b48700acdb
Don't refer to the system documentation as "man pages"; too
Fred Drake <fdrake@acm.org>
parents:
10595
diff
changeset
|
11 interpreting the results of \function{os.stat()}, |
|
19b48700acdb
Don't refer to the system documentation as "man pages"; too
Fred Drake <fdrake@acm.org>
parents:
10595
diff
changeset
|
12 \function{os.fstat()} and \function{os.lstat()} (if they exist). For |
|
19b48700acdb
Don't refer to the system documentation as "man pages"; too
Fred Drake <fdrake@acm.org>
parents:
10595
diff
changeset
|
13 complete details about the \cfunction{stat()}, \cfunction{fstat()} and |
|
19b48700acdb
Don't refer to the system documentation as "man pages"; too
Fred Drake <fdrake@acm.org>
parents:
10595
diff
changeset
|
14 \cfunction{lstat()} calls, consult the documentation for your system. |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
16 The \module{stat} module defines the following functions to test for |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
17 specific file types: |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 \begin{funcdesc}{S_ISDIR}{mode} |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
21 Return non-zero if the mode is from a directory. |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 \end{funcdesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 \begin{funcdesc}{S_ISCHR}{mode} |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
25 Return non-zero if the mode is from a character special device file. |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 \end{funcdesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 |
| 7177 | 28 \begin{funcdesc}{S_ISBLK}{mode} |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
29 Return non-zero if the mode is from a block special device file. |
| 7177 | 30 \end{funcdesc} |
| 31 | |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 \begin{funcdesc}{S_ISREG}{mode} |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
33 Return non-zero if the mode is from a regular file. |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 \end{funcdesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 \begin{funcdesc}{S_ISFIFO}{mode} |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
37 Return non-zero if the mode is from a FIFO (named pipe). |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 \end{funcdesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 \begin{funcdesc}{S_ISLNK}{mode} |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
41 Return non-zero if the mode is from a symbolic link. |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 \end{funcdesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 \begin{funcdesc}{S_ISSOCK}{mode} |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
45 Return non-zero if the mode is from a socket. |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
46 \end{funcdesc} |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
47 |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
48 Two additional functions are defined for more general manipulation of |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
49 the file's mode: |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
50 |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
51 \begin{funcdesc}{S_IMODE}{mode} |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
52 Return the portion of the file's mode that can be set by |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
53 \function{os.chmod()}---that is, the file's permission bits, plus the |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
54 sticky bit, set-group-id, and set-user-id bits (on systems that support |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
55 them). |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 \end{funcdesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 |
|
10733
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
58 \begin{funcdesc}{S_IFMT}{mode} |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
59 Return the portion of the file's mode that describes the file type (used |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
60 by the \function{S_IS*()} functions above). |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
61 \end{funcdesc} |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
62 |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
63 Normally, you would use the \function{os.path.is*()} functions for |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
64 testing the type of a file; the functions here are useful when you are |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
65 doing multiple tests of the same file and wish to avoid the overhead of |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
66 the \cfunction{stat()} system call for each test. These are also |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
67 useful when checking for information about a file that isn't handled |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
68 by \refmodule{os.path}, like the tests for block and character |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
69 devices. |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
70 |
|
61051fd65aab
Patch from Greg Ward adding descriptions of S_IMODE() and S_IFMT(),
Fred Drake <fdrake@acm.org>
parents:
10680
diff
changeset
|
71 All the variables below are simply symbolic indexes into the 10-tuple |
|
10678
19b48700acdb
Don't refer to the system documentation as "man pages"; too
Fred Drake <fdrake@acm.org>
parents:
10595
diff
changeset
|
72 returned by \function{os.stat()}, \function{os.fstat()} or |
|
19b48700acdb
Don't refer to the system documentation as "man pages"; too
Fred Drake <fdrake@acm.org>
parents:
10595
diff
changeset
|
73 \function{os.lstat()}. |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 \begin{datadesc}{ST_MODE} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 Inode protection mode. |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 \begin{datadesc}{ST_INO} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 Inode number. |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 \begin{datadesc}{ST_DEV} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 Device inode resides on. |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 \begin{datadesc}{ST_NLINK} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 Number of links to the inode. |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 \begin{datadesc}{ST_UID} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 User id of the owner. |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 \begin{datadesc}{ST_GID} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 Group id of the owner. |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 \begin{datadesc}{ST_SIZE} |
|
15800
3a260274bcc6
SourceForge patch #103140, checked in at fdrake's invitation. Minor fixes and
Eric S. Raymond <esr@thyrsus.com>
parents:
11173
diff
changeset
|
100 Size in bytes of a plain file; amount of data waiting on some special |
|
3a260274bcc6
SourceForge patch #103140, checked in at fdrake's invitation. Minor fixes and
Eric S. Raymond <esr@thyrsus.com>
parents:
11173
diff
changeset
|
101 files. |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 \begin{datadesc}{ST_ATIME} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 Time of last access. |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 \begin{datadesc}{ST_MTIME} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 Time of last modification. |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 \begin{datadesc}{ST_CTIME} |
|
7908
1a1d3147b027
Correct definition of CTIME.
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
113 Time of last status change (see manual pages for details). |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 \end{datadesc} |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 |
|
15800
3a260274bcc6
SourceForge patch #103140, checked in at fdrake's invitation. Minor fixes and
Eric S. Raymond <esr@thyrsus.com>
parents:
11173
diff
changeset
|
116 The interpretation of ``file size'' changes according to the file |
|
3a260274bcc6
SourceForge patch #103140, checked in at fdrake's invitation. Minor fixes and
Eric S. Raymond <esr@thyrsus.com>
parents:
11173
diff
changeset
|
117 type. For plain files this is the size of the file in bytes. For |
|
21062
bc02c3b09626
Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents:
15820
diff
changeset
|
118 FIFOs and sockets under most flavors of \UNIX{} (including Linux in |
|
bc02c3b09626
Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents:
15820
diff
changeset
|
119 particular), the ``size'' is the number of bytes waiting to be read at |
|
bc02c3b09626
Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents:
15820
diff
changeset
|
120 the time of the call to \function{os.stat()}, \function{os.fstat()}, |
|
bc02c3b09626
Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents:
15820
diff
changeset
|
121 or \function{os.lstat()}; this can sometimes be useful, especially for |
|
15820
33b444cbadb9
Fixed minor markup nits for consistency with the rest of the library
Fred Drake <fdrake@acm.org>
parents:
15800
diff
changeset
|
122 polling one of these special files after a non-blocking open. The |
|
33b444cbadb9
Fixed minor markup nits for consistency with the rest of the library
Fred Drake <fdrake@acm.org>
parents:
15800
diff
changeset
|
123 meaning of the size field for other character and block devices varies |
|
33b444cbadb9
Fixed minor markup nits for consistency with the rest of the library
Fred Drake <fdrake@acm.org>
parents:
15800
diff
changeset
|
124 more, depending on the implementation of the underlying system call. |
|
15800
3a260274bcc6
SourceForge patch #103140, checked in at fdrake's invitation. Minor fixes and
Eric S. Raymond <esr@thyrsus.com>
parents:
11173
diff
changeset
|
125 |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 Example: |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
7177
diff
changeset
|
128 \begin{verbatim} |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 import os, sys |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 from stat import * |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 |
|
11173
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
132 def walktree(dir, callback): |
|
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
133 '''recursively descend the directory rooted at dir, |
|
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
134 calling the callback function for each regular file''' |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 |
|
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 for f in os.listdir(dir): |
|
11173
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
137 pathname = '%s/%s' % (dir, f) |
|
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
138 mode = os.stat(pathname)[ST_MODE] |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 if S_ISDIR(mode): |
|
11173
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
140 # It's a directory, recurse into it |
|
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
141 walktree(pathname, callback) |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 elif S_ISREG(mode): |
|
11173
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
143 # It's a file, call the callback function |
|
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
144 callback(pathname) |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 else: |
|
11173
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
146 # Unknown file type, print a message |
|
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
147 print 'Skipping %s' % pathname |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 |
|
11173
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
149 def visitfile(file): |
|
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
150 print 'visiting', file |
|
4788
f2321e423071
Docs for stat.py -- docs by Skip Montanaro.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 |
|
10510
c3edc14c3880
Removed bosities around example code; not sure where that stuff crept
Fred Drake <fdrake@acm.org>
parents:
10335
diff
changeset
|
152 if __name__ == '__main__': |
|
11173
f766fb6f8526
Change the directory tree walking example to use clearer variable
Guido van Rossum <guido@python.org>
parents:
10733
diff
changeset
|
153 walktree(sys.argv[1], visitfile) |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
7177
diff
changeset
|
154 \end{verbatim} |
