Python: how to check if there are any files in the directory?

Please tell me how to use Python to check whether a certain direktoriji any files, not specifying exactly what (not pointing any names or extensions). Interested in just the fact of presence or absence. It is desirable that the script execution is not stopped on an error, and gave log ("file present"/"absent").
July 9th 19 at 12:48
2 answers
July 9th 19 at 12:50
Solution
import os

if os.listdir(path):
 #There are files
else:
 #No files
Why len? - glennie_Mer commented on July 9th 19 at 12:53
: an act of hooliganism :) - samir39 commented on July 9th 19 at 12:56
July 9th 19 at 12:52
import os
os.listdir(path) - displays a list of all files in the current folder
len(os.listdir(path)) - if the files must return a value other than 0, because the list is not empty in this case. If files or subdirectories not, it returns 0.

Find more questions by tags PythonTesting software