string - In python, how do I exclude files from a loop if they begin with a specific set of letters? -
I am writing a Python script that goes through a directory and collects some files, but I want to I have many files that are named in the file
Example code:
Name: if name! = "Doc1.html" and name! = "Doc2.html" and name! = "Doc3.html": print name
Assume that the directory contains 100 hundred HTML files, all of which are from the beginning 'doc'
. What would be the easiest way to get them out?
Sorry, I'm new to Python, I know that this is probably the basics.
Thanks in advance.
If the name is not there. Startswith ('doc'): Print name
If you have more prefixes to print the name, you can also do this:
< Code> if not name Startsless ('prefix', 'other', 'so far')): Print name / Pre>can accept a tuple of prefixes.
Comments
Post a Comment