0

there is a tool I write using python that analyze a pdf file by passing it in the cmd

c:\python "my_tool.py" -s "my_pdf.pdf"

I want to test the tool on 1000 files. how could I run the tool on all of the 1000 files.

I used this

for /f %%f in ('dir /b C:\Users\Test\Desktop\CVE_2010-2883_PDF_25files') do echo %%f

but how can I specify (the tool) and (-s) argument

2
  • Windows batch scripting isn't so nice, you might as well write a python program to do the job. Commented Sep 20, 2014 at 11:29
  • could you help me with that ? Commented Sep 20, 2014 at 11:52

4 Answers 4

1

Try like this :

@echo off
for /f %%f in ('dir /a-d/b C:\Users\Test\Desktop\CVE_2010-2883_PDF_25files\*.pdf') do (
  "c:\python\my_tool.py" -s "%%~dnxf")
Sign up to request clarification or add additional context in comments.

2 Comments

what if I want to scan all file in this directory? is it correct to do this: ('dir /a-d/b C:\Users\Test\Desktop\CVE_2010-2883_PDF_25files\*.) ... python it is not a directory it is an identifier
Use *.* in the place of *.pdf
0

you can use grep to pass all .pdf file to script !

c:\python grep *.pdf|"my_tool.py" -s 

or with this script :

for i in $(\ls -d *.pdf)
do
    python "my_tool.py" -s $i
done

1 Comment

the tool I wrote in windows. is there any possible way to do this?
0

If you have the Unix find command you can use

find . -type f -name "*.pdf" -exec c:\python "my_tool.py" -s {} \;

This runs your command on each of the pdf files in the current directory

1 Comment

I'm working on windows, do you know how to do this on windows ?
0

You can make your life a lot easier, by making sure the tool can just search a directory for all pdf files:

import glob
import os

def get_files(directory):
    for i in glob.iglob(os.path.join(directory, '*.pdf')):
       do_something(i)

if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', '--file', help='enter filename')
    parser.add_argument('-d', '--directory', help='enter directory of pdf files')
    args = parser.parse_args()
    if args.directory:
        get_files(args.directory)
    if args.file:
        do_something(args.file)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.