The newest file after unpacking file [python]
<p>When I'm unpack file, it is not the newest. Is there any chance to upack file and change its name so it is the newest file in the directory?</p>

<pre><code>print newest() #prints myFile.rar


if newest().endswith('.rar') or newest().endswith('.zip') :
    patoolib.extract_archive(newest(), outdir=".")
    #myFile.rar extracted to `.'. And it shows up in my directory myFile.pdf

time.sleep(20)
print  newest() #prints myFile.rar
</code></pre>

<p>My function:</p>

<pre><code>def newest():
    path = '/home/es/ajo/files'
    os.chdir(path)
    files = sorted(os.listdir(os.getcwd()), key=os.path.getmtime)
    newest = files[-1]
return str(newest)
</code></pre>

<p>It is really easy. After I unpack the file I just use function os.utime so unpacked file is the newest one in a directory :)
            ts = time.time()
            os.utime("/home/es/ajo/files/all")), (ts, ts))
It changes modified date. </p>

python python-2.7 file