apply command to list of files in python -
i've tricky problem. need apply specific command called xritdecompress list of files extension -c_ , should python.
unfortunately, command doesn't work wildcards , can't like:
os.system("xritdecompress *-c_") in principle, write auxiliary bash script for cycle , call inside python program. however, i'd not rely on auxiliary files...
what best way within python program?
you can use glob.glob() list of files on want run command , each file in list, run command -
import glob f in glob.glob('*-c_'): os.system('xritdecompress {}'.format(f)) from documentation -
the glob module finds pathnames matching specified pattern according rules used unix shell.
if _ (underscore) , wanted match single character , should use - ? instead , -
glob.glob('*-c?') please note, glob search in current directory according wanted original trial, seems maybe want.
you may also, want @ subprocess module, more powerful module running commands (spawning processes). example -
import subprocess import glob f in glob.glob('*-c_'): subprocess.call(['xritdecompress',f])
Comments
Post a Comment