0

I am trying to build a Python script wrapper to loop and run another python script called meioc against every file in a directory.

Essentially I have some old .eml / MIME encoded files I am using to anlyze headers & build a summary of each .eml using meioc.py.

Now I am trying to hack together this wrapper script to call meioc.py against all .eml in a directory. It is mostly working but I am hung up on the -o Output argument that meioc outputs.

This is the argument options for meioc.py;

meioc.py
usage: meioc.py [-h] [-x] [-s] [-o FILE_OUTPUT] [-v] filename
meioc.py: error: the following arguments are required: filename

And this is the script I am working on to have meioc.py cycle thru a entire directory;

# import required module
import os
import meioc 
# assign directory
directory = 'D:/eml_dir'
 
# iterate over files in
# that directory
for filename in os.listdir(directory):
    f = os.path.join(directory, filename)


    # checking if it is a file
    if os.path.isfile(f):
        #print(f)

                
        import subprocess
        meioc_cmd = ['python', 'meioc.py', '-o', (f), (f)]
        subprocess.call(meioc_cmd)

I am almost there but what I want is to have the output file be -o (f).txt , however I am having a heck of a time appending .txt to this variable.

meioc_cmd = ['python', 'meioc.py', '-o', (f)how to add .txt here?, (f)]

1 Answers1

0

If you are using python 3, you can use f-strings like f"{f}". This will interpolate the variable into your string.

If you are using python 2, you can do "{}".format(f).

meioc_cmd = ['python', 'meioc.py', '-o', f"{f}", f"{f}"]

or

meioc_cmd = ['python', 'meioc.py', '-o', "{}".format(f), "{}".format(f)]
myz540
  • 537
  • 4
  • 7