glob would work better, but if you really wanted to go the regex route, you could do something like this:
Code:
import os, re
# Create a regular expression object to match against
lock_re = re.compile('([.]*.lock)')
# grab a list of filenames in /home/dave/code
for filename in os.listdir('/home/dave/code'):
# check to see if the filename matches the regex
# this step could also be done like such:
# if filename.endswith('.lock'):
lockMatch = lock_re.search(filename)
if lockMatch is not None:
print "stuff is locked"
break
The same with glob would look something like this:
Code:
import glob
# check the current working directory...
# can use os.chdir to check a dir other than the cwd
filelist = glob.glob('*.lock')
if len(filelist) > 0:
print "stuff is locked"
else:
print "not locked"
glob would also be a better solution since you could then iterate over the filelist to see what exactly is locked.