How to compare the modified date of two files in python?
<p>I am creating a python script that will access each line from a Text file(say File.txt) one by one then search for corresponding '.py' and '.txt' file in the system directory. For example if "COPY"(the first line) is accessed from "File.txt" then search will be done for "COPY.py" and "COPY.txt". If both the files are found then their modification date will be compared. Code have no syntax error But I am getting the wrong output.</p>

<p><strong>My Python code is:</strong></p>

<pre><code>for line in fileinput.input(r'D:\Python_Programs\File.txt'):
    line = line[0:-1]
    sc = ''.join((line,'.py'))
    lo = ''.join((line,'.txt'))
    for root, dirs, files in os.walk(r'D:\txt and py'):
        if sc in files:
            pytime = time.ctime(os.path.getmtime(os.path.join(root, sc)))
            print(sc, '   :', pytime)
            for root, dirs, files in os.walk(root):
                if txt in files:
                    txttime = time.ctime(os.path.getmtime(os.path.join(root, txt)))
                    print(txt, '  :', txttime)
                    if (txttime &gt; pytime):
                        print('PASS', '\n')
                    else:
                        print('FAIL', '\n')
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>COPY.py     : Mon Aug 27 10:50:06 2012
COPY.txt    : Mon Feb 04 11:05:31 2013
PASS        #Expected = PASS

COPY2.py    : Fri Feb 08 16:34:43 2013
COPY2.txt   : Sat Sep 22 14:19:32 2012
PASS        #Expected = FAIL

COPY3.py    : Fri Feb 08 16:34:53 2013
COPY3.txt   : Mon Sep 24 00:50:07 2012
PASS        #Expected = FAIL
</code></pre>

<p>I am not getting why "COPY2" and "COPY3" are giving "PASS". May be I am doing it in a wrong way.
As well as on changing the comparison as <strong>"if (txttime &lt; pytime)"</strong> in the code.
All results are showing as "FAIL" in output.</p>
