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").
#There are files
Margarette.Casper answered on July 9th 19 at 12:52
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.