You could also switch to the target directory instead of constructing an absolute path.
def rmfiles(path, pattern):
pattern = re.compile(pattern)
oldpath = os.getcwd() # <--
os.chdir(path) # <--
try:
for each in os.listdir('.'):
if os.path.isdir(each) != True:
print(each + " not a dir")
if pattern.search(each):
name = os.path.join(path, each)
os.remove(name)
finally:
os.chdir(oldpath) # <--