Delete directories older than X days?
<p>I decided to go python for this because I am in the process of learning Python, so I use it over Powershell whenever I can.</p>

<p>I have the theory down for this, but it seems <code>os.stat</code> cannot take a list, but only a string or <code>int</code>.  Right now I'm just printing before I go and delete things.</p>

<pre><code>import os
import time

path = "\\\\path\\to\\videoroot\\"
now = time.time()
old = now - 1296000

for root, dirs, files in os.walk(path, topdown=False):
    if time.ctime(os.path.getmtime(dirs) &lt; old:
        print (dirs)
</code></pre>

<p>Output/error message:</p>

<pre class="lang-none prettyprint-override"><code>return os.stat(filename).st_mtime
    TypeError: argument should be string, bytes or integer, not list
</code></pre>

<p>Your code problem is that you are passing <code>dirs</code> to <code>os.path.getmtime()</code>, and <code>dirs</code> is a <code>list</code> as specified in the <a href="https://docs.python.org/2/library/os.html">documentation</a> for <code>os.walk</code></p>

<p>So you can address this by:</p>

<pre><code>import os
import time

path = "\\\\path\\to\\videoroot\\"
now = time.time()
old = now - 1296000

for root, dirs, files in os.walk(path, topdown=False):
    for _dir in dirs:
        if time.ctime(os.path.getmtime(_dir) &lt; old:
            print (_dir)
</code></pre>

python