How to execute an EXE via os.system() with spaces in the directory name?
rbt
rbt at athop1.ath.vt.edu
Tue Dec 6 08:20:27 EST 2005
jepler at unpythonic.net wrote:
> This comes up from time to time. The brain damage is all Windows', not
> Python's. Here's one thread which seems to suggest a bizarre doubling
> of the initial quote of the commandline.
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/89d94656ea393d5b/ef40a65017848671
I do this:
# remove spaces from ends of filenames.
for root, dirs, files in os.walk('programs'):
for fname in files:
new_fname = fname.strip()
if new_fname != fname:
new_path = os.path.join(root,new_fname)
old_path = os.path.join(root,fname)
os.renames(old_path,new_path)
# remove spaces from middle of filenames.
for root, dirs, files in os.walk('programs'):
for f in files:
new_f = string.replace(f, ' ' , '-')
new_path = os.path.join(root,new_f)
old_path = os.path.join(root,f)
os.renames(old_path,new_path)
# install files.
for root, dirs, files in os.walk('programs'):
installable = ['.exe', '.msi', '.EXE', '.MSI']
for f in files:
ext = os.path.splitext(f)
if ext[1] in installable:
print f
install = os.system(os.path.join(root,f))
More information about the Python-list
mailing list