1

I want to parsing some program's log and I want to check the existence of a core file in the log directory.

Assume the path is the log directory, and core file names always begins with string core (e.g., name is core.20161027.183805.28273.0001.dmp). Then is there any directed API I can use to check a core file in the path directory? Thanks

shijie xu
  • 1,975
  • 21
  • 52

3 Answers3

3

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

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
1

This may be dupe, is this the solution?

import os
os.path.isfile(os.path.join(path,corename))
kabanus
  • 24,623
  • 6
  • 41
  • 74
1

Also os lib can do the trick for you, returns true or false

import os

os.path.exists(dir_or_file_to_check)

BlackHawk
  • 37
  • 8