IOError: [Errno 13] Permission denied in python
<p>I have multiple files in 7 different folder directories. All of these files have the same name, and I want to combine those files with the same name as one file, in another directory</p>

<pre><code>import os
from itertools import chain

paths = (r'C:/Users/Test_folder/Input/', r'C:/Users/Test_folder/Input_2/')
for path, dirs, files in chain.from_iterable(os.walk(path) for path in paths):
    for fname in paths:
        for line in fname:
                f = open(os.path.join(r'C:/Users/Test_folder/Test_output/', os.path.basename(fname)), 'a')
                f.write ('{:}\n'.format(line))
                f.close()
</code></pre>

<p>Error:</p>

<pre><code>f = open(os.path.join(r'C:/Users/Test_folder/Test_output/', os.path.basename(fname)), 'a')
IOError: [Errno 13] Permission denied: 'C:/Users/Test_folder/Test_output/'
&gt;&gt;&gt; 
</code></pre>