Repeat the same analysis for TWO files in a lot of directories
<p>I have a lot of data stored in two files found in folders with the structure shown on this <a href="https://i.stack.imgur.com/zfFZW.png" rel="nofollow">pic</a>.
I wrote a small python script to process the two files in Subdir1 and would like to repeat it over Dir, so each Subdir gets visited. I searched stackoverflow and looked at ways of doing it:
     -either with bash (using a for loop to run the python script on all files)
     -or using os.walk() and walk Dir</p>

<p>The problem is that I have two files: I am getting some data from File_1, and some data from File_2, combining the two and then writing the resulting astropy Table (or dataframe) to a file. I can do this over one subdirectory. Any ideas how to do this for all the folders? </p>

<p>I can handle repeating tasks when there is only file per folder.
Thanks.</p>

<p>Something like this:</p>

<pre><code>subdirs = glob.glob("Dir/*/.")
for subdir in subdirs:
    file1 = os.path.join(subdir, "File_1")
    file2 = os.path.join(subdir, "File_2")
    result = os.path.join(subdir, "result.txt")
    with open(file1, "rt") as input_file1:
        with open(file2, "rt") as input_file2:
            with open(result, "wt") as output_file:
                # your computations go here:
                # input_file1.read()
                # output_file.write("these are my results")
</code></pre>

python bash