If Else with FIND command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zukizuki
Posts: 2
Joined: 18 Oct 2006 05:25

If Else with FIND command

#1 Post by zukizuki » 18 Oct 2006 05:56

Ok, I will try to explain as well as i can... (not having english as main lang.)

I'm having this batch script that's supposed to several things:

1. Check a directory for *.tbd (this is where the users put their files)
2. If *.tbd exist then continue with the rest of the script (as this script will run as a scheduled event every 20 or 30 mins or so)
3. Move the file to a certain folder
4. Here I'm using pgp to sign and encrypt the file
5. When pgp is done with its encryption etc the ftp session will commence
6. Im using this command: ftp -s:ftp.script IP.IP.IP.IP >ftp.log

7. Up to here im home safe... So now i have made an attempt to send the file via ftp to a distant location and also getting it written in my log file. So far, no worries. Next step is where could use some help.

So, to the question:
How am I able to scan the ftp.log file for a text string such as "226 File received ok." in order to know that the transfer succeeded? The log file always display that text string once the ftp been successful. What im looking for is something like:

8. Does that text string called "226 File received ok." exist in ftp.log? then goto :JOY if not go to :SAD

:JOY
Send_OK_email.vbs
continue with script, move files etc....
:SAD
Send_email_to_admin.vbs
end script etc.

Im wrestling with the FIND command to be used in an IF ELSE session. Is this possible or am i completely lost? (prolly the latter... ;-) )

Would be grateful for any input!

Regards,

zukizuki

zukizuki
Posts: 2
Joined: 18 Oct 2006 05:25

#2 Post by zukizuki » 18 Oct 2006 08:35

Well, had to search a bit more and found it to be....quite simple actually hehe......*sigh* At least it solved my little issue!


This is what i used:
*********************************
FIND "226 File received ok." 1.log > nul
if errorlevel=1 GOTO :NO
if not errorlevel=1 GOTO :YES

:YES
echo. YEEEES!
GOTO END

:NO
echo. NOOOOO!
GOTO END

:END

*********************************

Regards,

zukizuki

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: If Else with FIND command

#3 Post by Samir » 10 Feb 2014 13:41

I hate to bump an old thread, but I'm having trouble getting this to work. :(

It seems like the errorlevel just isn't begin registered by find to be checked by if.

I've used if else in the following:

Code: Select all

FIND "/14/14" IMPORT > NUL
IF ERRORLEVEL 1 (
S:\SCRIPTS\REPLACE.BAT /14/14 /14'14 IMPORT > ..\..\IMPORT.QIF
) ELSE (
S:\SCRIPTS\REPLACE.BAT /14 '14 IMPORT > ..\..\IMPORT.QIF
)

IMPORT does contain the string, but it's always executing the else section of the if else. Any ideas why?

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: If Else with FIND command

#4 Post by Samir » 10 Feb 2014 13:57

Oops! I think I figured it out. I was using errorlevel 1 as being successful. :oops:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: If Else with FIND command

#5 Post by foxidrive » 10 Feb 2014 15:38

Did you use

Code: Select all

 IF NOT ERRORLEVEL 1

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: If Else with FIND command

#6 Post by Samir » 27 Feb 2014 11:11

foxidrive wrote:Did you use

Code: Select all

 IF NOT ERRORLEVEL 1
No, I just swapped my branches since I did want to still use the same check. Everything worked fine until today.

And I don't think this piece of code is even related, since the previous version of this batch without this if else in it also fails to work correctly, but for some reason, a file is not being read like it used to be. Very dumbfounding.

Post Reply