File existence check with partial filename
Lan Qing
efiish at gmail.com
Mon Mar 15 06:57:38 EDT 2010
Or use the regular module:
import re
import os
for filename in os.listdir('.'):
if re.match("*HV*", filename):
# do something with the file
On Mon, Mar 15, 2010 at 12:24 PM, Alf P. Steinbach <alfps at start.no> wrote:
> * Sang-Ho Yun:
>
> I learned that I can check the existence of a file using
>> os.path.isfile("filename").
>>
>> What if I need to check if there is a file that contains "HV" in the
>> filename? What should I do?
>>
>
> <code>
> from __future__ import print_function
> import os
for filename in os.listdir( "." ):
> if "HV" in filename.upper():
> print( filename )
> </code>
>
>
> Cheers & hth.,
>
> - Alf
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100315/ff8fcd8b/attachment-0001.html>
More information about the Python-list
mailing list