import os, time, sys

import datetime
import stat

now1 = time.time()

twohoursago= now1 - 60*60*60*2
print (twohoursago)

def getListOfFiles(dirName):
# create a list of file and sub directories
# names in the given directory
    listOfFile = os.listdir(dirName)
    allFiles = list()
# Iterate over all the entries
    for entry in listOfFile:
    # Create full path
        fullPath = os.path.join(dirName, entry)
    # If entry is a directory then get the list of files in this directory 
        if os.path.isdir(fullPath):
            allFiles = allFiles + getListOfFiles(fullPath)

    return allFiles        

def main():

    dirName = '/Users/lokeshmanchi/test-script';

    # Get the list of all files in directory tree at given path
    listOfFiles = getListOfFiles(dirName)

    # Print the files
    print ("****************") 
   # Get the list of all files in directory tree at given path
    listOfFiles = list()
    for (dirpath, dirnames, filenames) in os.walk(dirName):
        listOfFiles += [os.path.join(dirpath, file) for file in       

    # Print the files    
    for elem in listOfFiles:
#   print(os.path.getctime("$s",elem))
    time_str = str(elem)
    timestamp = (os.path.getctime(time_str))
    print (timestamp)
    if timestamp <  twohoursago:
        print "File is more than 2 hours old"

    print (a)

if __name__ == '__main__':

So it keeps returning that all the files are older than 2 hours old

closed as off-topic by Mokubai Dec 6 at 16:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about computer hardware or software, within the scope defined in the help center." – Mokubai
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.