Reputation:
I have been scratching my head for a few days trying to get this to work. I am trying to write a batch script to look for text in a PDF file and move said file to a folder. Sounds simple but i have failed to get a for loop to parse a variable. This is what i have so far:
@echo off
SetLocal
setlocal enabledelayedexpansion
set dir=C:\Pdf Invoices
set inc=C:\Pdf Invoices\ESD\Includes
title Signing Invoices
echo Signing Invoices.....
echo.
:Movefiles
REM Check "IN" folder for invoices
if exist "%dir%\In\*.pdf" (goto MOVEFORPROCESSING) else (goto END)
:MOVEFORPROCESSING
for /f %%a in ('DIR /b "%dir%\In\*.pdf"') do (
move "%dir%\In\%%a" "%dir%\ESD\Processing\" >nul
)
for /r "%dir%\ESD\Processing" %%F in (*.pdf) do (
set type="%inc%\pdftextreplacer_cmd\pdftr.exe" -searchtext "USD" "%%F" | find /C "USD"
If "%type%" == "0" (
echo File is ZAR
) else (
echo File is USD
)
)
:END
Basically if the file contains USD move to USD folder and IF file contains "ZAR" move to "ZAR" folder. I am using pdftextreplacer to search the pdf files which works fine.
Any help would be greatly appreciated.
Upvotes: 3
Views: 5607
Reputation: 70923
Posible problem with white spaces
for /F "tokens=*" %%a in (.....
Posible delayed expansion problem with variable %type%
EXISTS problem with logic of setting variable %type%. You can no set a variable to a return value of a executing command. Rewrite to
"%inc%\pdftextreplacer_cmd\pdftr.exe" -searchtext "USD" "%%F" | find "USD" >nul
if errorlevel 1 (
echo File is ZAR
) else (
echo File is USD
)
Upvotes: 3