一个获取当前目录以及只目录下某类文件的脚本


               
               
                #!/usr/bin/env python
import os,re,subprocess
# init dir
dirname = os.getcwd()
# init filelist
filelist = [os.path.join(dirname, f) for f in os.listdir(dirname)]# if os.path.isdir(os.path.join(dirname, f))]   #list
while 1:
    has_dir = 0  #no dir
    for f in filelist:
    if os.path.isdir(f):
        has_dir = 1 # has dir
        filelist.remove(f) # remove form list
        dirname = f  # refresh dir
        filelist.extend([os.path.join(dirname, f) for f in os.listdir(dirname)])
    if 0 == has_dir: # no dir ,break of while
    break
#print len(filelist)
# clean first
while 1:
    has_clean = 0
    for file in filelist:
    if None != re.search('\.[bB][iI][nN]$',file):
        has_clean = 1
        filelist.remove(file)
    if re.search('\.[hH][eE][xX]$',file):
        has_clean = 1
        filelist.remove(file)
    if re.search('\.[eE][xX][eE]$',file):
        has_clean = 1
        filelist.remove(file)
    if re.search('\.[pP][yY]$',file):
        has_clean = 1
        filelist.remove(file)
    if 0 == has_clean:
    break
#print len(filelist)
# elf ==> bin
for file in filelist:
    ps_id = subprocess.Popen('arm-elf-objcopy.exe -O binary %s %s.bin' %(file,file), shell=True)
    ps_id.wait()
# bin ==> hex
for file in filelist:
    ps_id = subprocess.Popen('bin2hex.exe %s.bin %s.hex' %(file,file), shell=True)
    ps_id.wait()