python - How to select specific filenames nested within several folders? -
i have working folder on "c:\users\username\desktop\test" python test script located. idea import directory drive ("d:\mydir\mytests\projects") current working directory:
import os os import getcwd curdir=os.getcwd() path = os.chdir(os.path.join(curdir,"d:\mydir\mytests\projects"))
under "projects" directory there several folders contain subfolders (but not every). trieng make kind of generic code iterate on "projects" directory access every folder or subfolder if exist , find specific files ".proj" extension. found files (".proj") should writen out in form of list (maybe) can run each of them 1 one loop. tried write down code not successfully. suggestion appreciated lot.
proj_list = [] dirpath, dirnames, files in os.walk(path): f in files: dest_dir = glob.glob('*.proj') fullpath = os.path.join(dirpath, f.dest_dir) proj_list.append(fullpath) def activate_approval(dialog): dialog.activate_button('yes') class openallprojectsfromlistandrun(script.testscript): def test_run (self): project in fullpath: self.handle_dialog(activate_yes): self.open_project(project) '''nothing in particular''' if __name__ == '__main__': test = openallprojectsfromlistandrun() test.run()
ps: i'm using python 2.7
Comments
Post a Comment