Reputation: 115
My title might be misleading, as it's just a part of my question. My current code is as shown below, it is not completed as i am not good with for loop
import os
import subprocess
listfile = []
path = "C:\\Users\\A\\Desktop\\Neuer Ordner (3)"
for f in os.listdir(path):
if f.endswith(".par"):
listfile.append(f)
print listfile
it's output is as shown below:
C:\app\Tools\exam\Python25>python nwe.py
['abc.par', 'abc2.par', 'abc3.par', 'abc4.par', 'abc5.par', 'abc6.par', 'abc7.pa
r', 'abc8.par', 'abc9.par']
Now i have to call a perl file, say "Newperl.pl" with arguments arg1 as abc.par and arg2 as abc.svl arg1 as abc2.par and arg2 as abc2.svl arg1 as abc3.par and arg2 as abc3.svl
It has to take all the files which ends with ".par" extension and pass the the filename as argument while adding ".par" to the 1st argument and ".svl" to the 2nd argument. i can use the one below for for loop.
for i in range(0,len(listfile), 1)
newcode = subprocess.call()
2nd line calls the perl file, but i am not sure as in how to split the ".par" and add ".par" and ".svl" again and pass each one at a time. any logic or help would be appriciated
Upvotes: 0
Views: 47
Reputation: 4318
You could write your subprocess call as below:
import os
for l in listfile:
newcode = subprocess.call("perl newperl.pl "+l+" "+os.path.splitext(l)[0]+'.svl')
os.path.splittext
remove the extension for par files and adds svl extension.
Upvotes: 1