利用 os.stat 判断文件是否损

来源:互联网 发布:pump it up 编辑:程序博客网 时间:2024/06/01 10:20


This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file seeopen(), if you want to manipulate paths, see theos.path module, and if you want to read all the lines in all the files on the command line see thefileinput module. For creating temporary files and directories see thetempfile module, and for high-level file and directory handling see theshutil module.

Notes on the availability of these functions:

  • The design of all built-in operating system dependent modules of Python is such that as long as the same functionality is available, it uses the same interface; for example, the functionos.stat(path) returns stat information about path in the same format (which happens to have originated with the POSIX interface).
  • Extensions peculiar to a particular operating system are also available through theos module, but using them is of course a threat to portability.
  • An “Availability: Unix” note means that this function is commonly found on Unix systems. It does not make any claims about its existence on a specific operating system.
  • If not separately noted, all functions that claim “Availability: Unix” are supported on Mac OS X, which builds on a Unix core.

Note

All functions in this module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system.

exceptionos.error
An alias for the built-in OSError exception.

利用 os.stat 判断文件是否损坏

    for folder in folders:

        p = os.path.join( path, folder )
        try:
            os.stat( p )
        except OSError as e:
            all_folder_good = False
            continue

    

0 0
原创粉丝点击