# Move PDFs based on keyword in content



## TechGuy (Feb 12, 1999)

I need to move a bunch of PDF documents based on keywords inside of them. For example, if the keyword "TechGuy" is in a PDF, I'd like it to go to c:\Docs\TechGuy

I found pdfgrep.exe, which will allow me to search for keywords in PDFs and will give me the following results:

C:\Scans>pdfgrep.exe TechGuy *.pdf -r -H -c
2013_03_05_14_42_01.pdf:15
2013_03_05_14_43_57.pdf:7

So I need some way for a batch script (or PowerShell if necessary) to read through those results, ignore the number of hits at the end of the filename 15, :7, etc) and move those files to a specified folder.

Thanks!


----------



## Squashman (Apr 4, 2003)

```
FOR /F "Tokens=1 delims=:" %%G IN ('pdfgrep.exe TechGuy *.pdf -r -H -c') DO move "%%~G" "C:\Docs\Techguy"
```
As long as your file names do not have colons in them this should work.


----------



## TechGuy (Feb 12, 1999)

Thanks for the quick reply!

Upon further testing, it seems that my solution will have to be a bit more complicated... If the keyword is not found in the PDF, greppdf still lists the file name, but with a :0 at the end. Can you adjust for that?

Sample output where keyword is matched 0 times in the first PDF and 15 times in the second:

C:\Scans>pdfgrep.exe CenturyLink *.pdf -r -H -c
2013_03_05_14_43_57.pdf:0
2013_03_05_18_18_35.pdf:15


----------



## Squashman (Apr 4, 2003)

Yep.

```
FOR /F "Tokens=1-2 delims=:" %%G IN ('pdfgrep.exe TechGuy *.pdf -r -H -c') DO (
     IF NOT "%%H"=="0" move "%%~G" "C:\Docs\Techguy"
)
```


----------



## TechGuy (Feb 12, 1999)

Great!! I'm not in the office today due to the snow, but will give this a try tomorrow. Thanks for your help!


----------



## TechGuy (Feb 12, 1999)

It works perfectly! (As if you would expect anything less...  )

Thanks again!


----------



## Squashman (Apr 4, 2003)

I like the pdfgrep tool. I had never had the need to do something like that but I might in the future.


----------



## ckphilli (Apr 29, 2006)

It does look very useful. :up:


----------

