# Copies files in a specified subdirectory to other subdirectories, and runs # them. import os import shutil # Change to directory where script is located abspath = os.path.abspath(__file__) dname = os.path.dirname(abspath) os.chdir(dname) # Specify the subdirectory to copy the files from sourcedir = 'CopySource' # Get all the subdirectories. Copy to all of these by default, can manually # add exceptions if required. dirlist = next(os.walk('.'))[1] # Get a list of all the files in the source directory filelist = os.listdir(dname+'/'+sourcedir) for dirc in dirlist: # Add exceptions to directories here, if necessary. These are the destination # directories. if 'CopySource' not in str(dirc): destination = dname+'/'+dirc+'/' for filename in filelist: shutil.copy(dname+'/'+sourcedir+'/'+filename, destination) # Now go through each of the destination directories and run the program for dirc in dirlist: # Add exceptions to directories here, if necessary. These are the destination # directories. if 'CopySource' not in str(dirc): os.chdir(dname+'/'+dirc) os.system('gfortran -o massposvelacc massposvelacc.f') os.system('./massposvelacc')