I’m writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.
Example code:
for name in files:
if name != "doc1.html" and name != "doc2.html" and name != "doc3.html":
print name
Let’s say there are 100 hundred HTML files in the directory all beginning with 'doc'. What would be the easiest way to exclude them?
Sorry I’m new to Python, I know this is probably basic.
Thanks in advance.
If you have more prefixes to exclude you can even do this:
startswith can accept a tuple of prefixes.