Python Automation and Machine Learning for EM and ICs

An Online Book, Second Edition by Dr. Yougui Liao (2019)

Python Automation and Machine Learning for EM and ICs - An Online Book

Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

Check Whether or Not a Folder Contains Specific Files

The Python script (Code) is designed to verify the contents of a specified folder by checking for the presence and absence of specific files. It defines two sets: one containing the required files ("1a.tif", "1b.ppt", and "c.gif") that must exist in the folder, and another containing the forbidden files ("de.tif" and "u.tif") that must not be present. By listing all filenames in the folder using os.listdir() and converting them to a set, the script uses set operations to determine whether all required files are included and none of the forbidden files are present. If the folder meets these conditions, it confirms compliance; otherwise, it identifies which required files are missing or which forbidden files are found. This script is useful for automating content validation in file system workflows.