I am trying to find a folder with a '.tmp' extension in a directory and all its sub-directories (and all its subsequent sub-directories). Basically a folder with '.tmp' extension anywhere in a particular path.
As of now, I am only able to find a folder with .tmp extension in a particular directory but not in its subsequent directories. Kindly help.
Code:
def main():
"""The first function to be executed.
Changes the directory. In a particular directory and subdirectories, find
all the folders ending with .tmp extension and notify the user that it is
existing from a particular date.
"""
body = "Email body"
subject = "Subject for the email"
to_email = "subburat@synopsys.com"
# Change the directory
os.chdir('/remote/us01home53/subburat/cn-alert/')
# print [name for name in os.listdir(".") if os.path.isdir(name)]
for name in os.listdir("."):
if os.path.isdir(name):
now = time.time()
if name.endswith('.tmp'):
if (now - os.path.getmtime(name)) > (1*60*60):
print('%s folder is older. Created at %s' %
(name, os.path.getmtime(name)))
print('Sending email...')
send_email(body, subject, to_email)
print('Email sent.')
if __name__ == '__main__':
main()
Operating System: Linux; Programming Language Python