@@ -73,6 +73,34 @@ for each test. These are also useful when checking for information about a file
7373that isn't handled by :mod: `os.path `, like the tests for block and character
7474devices.
7575
76+ Example::
77+
78+ import os, sys
79+ from stat import *
80+
81+ def walktree(top, callback):
82+ '''recursively descend the directory tree rooted at top,
83+ calling the callback function for each regular file'''
84+
85+ for f in os.listdir(top):
86+ pathname = os.path.join(top, f)
87+ mode = os.stat(pathname)[ST_MODE]
88+ if S_ISDIR(mode):
89+ # It's a directory, recurse into it
90+ walktree(pathname, callback)
91+ elif S_ISREG(mode):
92+ # It's a file, call the callback function
93+ callback(pathname)
94+ else:
95+ # Unknown file type, print a message
96+ print('Skipping %s' % pathname)
97+
98+ def visitfile(file):
99+ print('visiting', file)
100+
101+ if __name__ == '__main__':
102+ walktree(sys.argv[1], visitfile)
103+
76104All the variables below are simply symbolic indexes into the 10-tuple returned
77105by :func: `os.stat `, :func: `os.fstat ` or :func: `os.lstat `.
78106
@@ -262,31 +290,47 @@ The following flags can also be used in the *mode* argument of :func:`os.chmod`:
262290
263291 Unix V7 synonym for :data: `S_IXUSR `.
264292
265- Example: :
293+ The following flags can be used in the * flags * argument of :func: ` os.chflags ` :
266294
267- import os, sys
268- from stat import *
295+ .. data :: UF_NODUMP
269296
270- def walktree(top, callback):
271- '''recursively descend the directory tree rooted at top,
272- calling the callback function for each regular file'''
297+ Do not dump the file.
273298
274- for f in os.listdir(top):
275- pathname = os.path.join(top, f)
276- mode = os.stat(pathname)[ST_MODE]
277- if S_ISDIR(mode):
278- # It's a directory, recurse into it
279- walktree(pathname, callback)
280- elif S_ISREG(mode):
281- # It's a file, call the callback function
282- callback(pathname)
283- else:
284- # Unknown file type, print a message
285- print('Skipping %s' % pathname)
299+ .. data :: UF_IMMUTABLE
286300
287- def visitfile(file):
288- print('visiting', file)
301+ The file may not be changed.
289302
290- if __name__ == '__main__':
291- walktree(sys.argv[1], visitfile)
303+ .. data :: UF_APPEND
304+
305+ The file may only be appended to.
306+
307+ .. data :: UF_OPAQUE
308+
309+ The file may not be renamed or deleted.
310+
311+ .. data :: UF_NOUNLINK
312+
313+ The directory is opaque when viewed through a union stack.
314+
315+ .. data :: SF_ARCHIVED
316+
317+ The file may be archived.
318+
319+ .. data :: SF_IMMUTABLE
320+
321+ The file may not be changed.
322+
323+ .. data :: SF_APPEND
324+
325+ The file may only be appended to.
326+
327+ .. data :: SF_NOUNLINK
328+
329+ The file may not be renamed or deleted.
330+
331+ .. data :: SF_SNAPSHOT
332+
333+ The file is a snapshot file.
334+
335+ See the \* BSD or Mac OS systems man page :manpage: `chflags(2)` for more information.
292336
0 commit comments