1

Basically I just want go through every line in my PE.tmp file and lookup those in test.txt and just call another procedure if found or not.

Script

SET "sourcedir=D:\"
SET "FN=%sourcedir%test.txt"

FOR /F "TOKENS=1 DELIMS=." %%A IN (PE.tmp) DO (
FOR /F "TOKENS=1 DELIMS=." %%A IN ('FINDSTR /L /c:"%%A" "%FN%"' set "valpdf=%%A") DO IF %ErrorLevel% EQU 0 (
call :found 
    ) ELSE (
        call :notfound 
        )
)
:found
echo %valpdf%.PDF - %DATE% %time% - Found > LOG.txt
type log.txt >> log1.txt

:notfound
echo %valpdf%.PDF - %DATE% %time% - Not Found > LOG.txt
type log.txt >> log1.txt

Test.txt

Remote working directory is /
New local directory is D:\PP
local:PP65205861.PDF => remote:/PP65205861.PDF
Listing directory /
-rw-------   1 200      100         12414 June 03 20:05 PP65205861.PDF
New local directory is D:\PE
local:PP65205862.PDF => remote:/PP65205862.PDF
Listing directory /
-rw-------   1 200      100          6763 June 03 20:05 PP65205862.PDF
New local directory is D:\TEMP
Listing directory /
*.PDF: nothing matched

PE.tmp

PP65205861.PDF
PP65205862.PDF

My Result

.PDF - 05/05/2017 10:56:39.59 - Found 
.PDF - 05/05/2017 10:56:39.60 - Not Found 

Desired Result

PP65205861.PDF - 05/05/2017 10:56:39.59 - Found 
PP65205862.PDF - 05/05/2017 10:56:39.59 - Found 

Script that work

SET "sourcedir=D:\"
SET "FN=%sourcedir%test.txt"


FOR /F "delims=" %%f in (PE.tmp) do (
 FINDSTR /M /C:%%f %FN%>NUL:
  IF errorlevel 1 (
    ECHO %%f - %DATE% %time%  >> log.txt
  ) ELSE (
    ECHO %%f - %DATE% %time%  >> log.txt

  )
)
sccydd
  • 23
  • 6
  • 1) you've got a severe syntax problem in your second `FOR` line. 2) you need [delayed expansion](http://stackoverflow.com/a/30284028/2152082) for `errorlevel` 3) there is no code to remove unwanted data. – Stephan May 05 '17 at 08:38
  • 4) Main program and subs need to end with a `Goto :Eof` or `Exit /B` –  May 05 '17 at 10:15
  • 5) You can't stack two `For /f ` loops using the same var `%%A` –  May 05 '17 at 10:34
  • 2
    @LotPings 5) actually, you can (and it works). But agreed: not advisable at all. – Stephan May 05 '17 at 11:08
  • [`findstr`](http://ss64.com/nt/findstr.html) takes an argument `/G` where you can provide a file that holds search strings: `findstr /L /G:"PE.tmp" "%FN%"`. Your 2nd `for /F` loop cannot work: 1. you quoted the command lie to parse wrongly; 2. there is an escaped `&` missing; for the syntax, it should read `for /F %%A in ('findstr /L /C:"%%A" "%FN%" ^& set "valpdf=%%A"') do ( ... )`, but even this fails, because the set variable is lost, because it is done in a separate `cmd` instance initiated by `for /F`... – aschipfl May 05 '17 at 12:40

1 Answers1

0

To get your desired result, this should do:

:: Q:\Test\2017-05\05\SO_43795847.cmd
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
Set "sourcedir=D:\"
Set "FN=%sourcedir%test.txt"

For /F "DELIMS=" %%A IN (PE.tmp) DO (
    Set "Found=Not Found"
    FOR /F "DELIMS=" %%B IN ('FINDSTR /L /c:"%%A" "%FN%"' ) DO Set "Found=Found"
    Echo %%A - %DATE% %time% - !Found! > LOG.txt
    Type log.txt >> log1.txt
)