Reputation: 3
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
Upvotes: 0
Views: 81
Reputation: 9545
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")
Upvotes: 1
Reputation: 174624
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)
Upvotes: 0
Reputation: 29317
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
Upvotes: 0
Reputation: 107287
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
Upvotes: 0