how to check existence of a core files in directory using Python

This question already has an answer here:

  • How to check whether a file exists? 39 answers

  • Use the built-in glob module:

    import glob
    if glob.glob('/path/to/dir/core*'):
        print('At least one core file present in /path/to/dir')
    

    More reading here: https://docs.python.org/3/library/glob.html


    这可能是愚蠢的,这是解决方案吗?

    import os
    os.path.isfile(os.path.join(path,corename))
    

    另外os lib可以为你做诡计,返回true或false

    import os

    os.path.exists(dir_or_file_to_check)

    链接地址: http://www.djcxy.com/p/7312.html

    上一篇: 如何检查argv是否引用python2.7中的现有文件?

    下一篇: 如何使用Python检查目录中核心文件的存在