Q:

Recursively convert DOS files to UNIX format in Python

I have a function that I use to organize files into folders. However, I would like to be able to have this function also recursively convert the files from DOS to UNIX as part of the routine. I know about the dos2unix command, but I keep getting a syntax error when I try to use it (dos2unix file    SyntaxError: invalid syntax). I'm not sure why though. 
Here's the function I'm running
def listFiles(aname,nAtoms): #This function organizes the .run files for all atoms into folders

iniPath = os.getcwd()
runfiles = []
folders  = []

filenames= os.listdir (".")

#This populates the list runfiles with any files that have a .run extension
for file in glob.glob("*.run"):
    dos2unix file
    runfiles.append(file)

#This populates the list folders with any folders that are present in the current working directory
for file in filenames:
    if os.path.isdir(os.path.join(os.path.abspath("."), file)):
        folders.append(file)

#Perform a natural sort of the files and folders (i.e. C1,C2,C3...C10,C11,etc, instead of C1,C10,C11...C2,C3)
natSortKey = natsort_keygen(key=lambda y: y.lower(), alg=ns.IGNORECASE)

runfiles.sort(key = natSortKey)
folders.sort(key = natSortKey)

#This loop moves the files to their respective atom folders and deletes the version in the original directory
i = 1
nf = 0
for i in range(0,nAtoms + 1):
    atomDir = aname + str(i)
    for item in runfiles:
        if item.startswith(atomDir):
            if nf >= i*5:
                break
            else:
                shutil.copy(path.join(iniPath,item),atomDir)
                os.remove(item)
                nf += 1        

print("The files are:")
print(runfiles,"\n")

print("The folders are:")
print(folders,"\n")   

Any suggestions? 
Thanks!

A:

Recursively for all files in the dosdir directory.
import os
os.system("find dosdir -type f -exec dos2unix -u {} \; ");

requires the find and dos2unix system commands, mostly this is true by default.

