Python: run script in all subdirectories
<p>I am new to Python and I am using it to do some data analysis. </p>

<p>My problem is the following: I have a directory with many subdirectories, each one of which contains a large number of data files.</p>

<p>I already wrote a Python script which, when executed in one of those subdirectories, performs the data analysis and writes it on a output file. The script includes some shell commands that I call using <code>os.system()</code>, so I have to "be" in one of the subdirectories for it to work.</p>

<p>How can I write a function that automatically:</p>

<ol>
<li>Moves into the first subdirectory</li>
<li>Executes the script</li>
<li>Goes back to the parent directory and moves to the next subdirectory</li>
</ol>

<p>I guess that this could be done in some way using <code>os.walk()</code> but I didn't really understand how it works.</p>

<p>PS I am aware of the existence of <a href="https://stackoverflow.com/questions/15005476/run-python-script-on-all-subdirectories-with-specific-name">this post</a> but it doesn't solve my problem. </p>

<p>PPS Maybe I should point out that my function does not take the directory name as argument. Actually it takes no argument.</p>