Jump to content
Mr Dump

Advice please-best way to approach this

Recommended Posts

I was wondering what would be the best way to automate this task I regularly do- Zzozzach's scripting question sort of looks along the lines but ... well, im new to this....

anyway heres what I do :


get a text list of variable names


search (I just cut/paste each lineone at a time into the windows explorer search bar - the actual search is surprisingly quick- i believe it is an indexed search)

for instance/s of that name in files in particular directories, the files of interest are *.c *.h *.doc *.pdf


make note of the hits




I sometimes have 60 or so variable names, and it is a very slow process, which i'd love to automate.

The directories have about 4000 .c, .h files, and there are about 200 procedures .pdf,.doc.

It would be so good to have a text output that I can sort through, so as to match up what variables are set by what procedure and which c modules I need to grab to look in.


Is powershell scripting a suitable way to do this?

Is there a way to get a variable passed to the explorer search?


Laptop is W7, I have admin rights, btw.


Any pointers appreciated!

Share this post

Link to post
Share on other sites

Good old windows batch files can do the text files:


Batch file (find_vars.bat):

FOR /F %%G IN (vars.txt) DO FINDSTR /S /N /C:"%%G" *.c *.h *.py

And of course vars.txt looks like:


DOC files probably won't work, PDF technically should (most postscript is just text) but I can't guarantee it.


/edit I had *.py in there for my testing across a python project.

Also have you looked into search and replace tools?

Edited by SledgY

Share this post

Link to post
Share on other sites

thanks guys, I just found the select-string term for powershell, after a days manual reading, and then the dos findstr popped up ha ha! - I am more comfortable with batch files so I'll try follow that path first! Thanks sledgy I'll muck around with this, get my head around the parameters and see how I go! (will report in a day or three, depending on work madness!)

stoked! thanks again!

Share this post

Link to post
Share on other sites

Can help with an explaination:

FOR /F %%G IN (vars.txt) DO FINDSTR /S /N /C:"%%G" *.c *.h *.py


/F - loop over a text file and populate the variable %%G with each line



/S - search through sub directories

/N - prints the line number prior to each match (added as it's kind of useful information!)

/C - tells findstr to do a literal search using the supplied value, in this case the value stored in the %%G variable

Share this post

Link to post
Share on other sites

Hi there, the findstr works pretty well, however I am having issues getting a redirect to a file working, e.g. >list.txt but I workaournd by using the select all / copy text option of the cmd window. Also not successful with parsing *.pdf as yet, but that has been an issue in the explorer search bar too, so I am wondering if that stems from the windows indexing function...

Anyway, i'm getting output, so i'm stoked! thanks

Share this post

Link to post
Share on other sites

There are tools that will let you search inside of a PDF.


One option is to use a tool like pdftohtml (from the poppler tool suite, there is a windows version) to extract text and from that do a search.


Alternatively the PyPDF library is a python library that can be used to manipulate and extract text from a PDF file.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now