Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find string ?

38 views
Skip to first unread message

Docfxit

unread,
Jan 6, 2018, 11:51:11 AM1/6/18
to
I currently have this line:
type "%~dp0BootFixerTest.txt" |find /i "Windows installations: 0" >nul || goto :Done

It's not working correctly.
I believe it's currently going to :Done
Because "Windows installations: 0" is not in the file I don't want it to go to :Done.

This is what is in the file:
Scanning all disks for Windows installations.

Please wait, since this may take a while...

Successfully scanned Windows installations.
Total identified Windows installations: 2
[1] \\?\GLOBALROOT\Device\HarddiskVolume4\Windows
[2] \\?\GLOBALROOT\Device\HarddiskVolume2\WINDOWS
The operation completed successfully.

Thanks,
Docfxit

JJ

unread,
Jan 7, 2018, 1:14:39 PM1/7/18
to
On Sat, 6 Jan 2018 08:51:09 -0800 (PST), Docfxit wrote:
> I currently have this line:
> type "%~dp0BootFixerTest.txt" |find /i "Windows installations: 0" >nul || goto :Done
>
> It's not working correctly.
> I believe it's currently going to :Done
> Because "Windows installations: 0" is not in the file I don't want it to go to :Done.
[snip]

If the text is not found, the execution will jump to the :Done label.
Otherwise it continues to the next line.

Docfxit

unread,
Jan 7, 2018, 3:50:07 PM1/7/18
to
How could I change it so it goes to Done only if the text is found?

Thank you,

Docfxit

Batchman

unread,
Jan 7, 2018, 7:04:41 PM1/7/18
to
Docfxit wrote:


> How could I change it so it goes to Done only if the text is found?

Possibly try testing the errorlevel returned by find...

If errorlevel==1 goto :Done

I'm guessing that find returns 0 (zero) when it finds the required string
and 1 (one) when it doesn't.

Batchman

unread,
Jan 8, 2018, 4:43:24 PM1/8/18
to
Batchman wrote:

> Batchman wrote:
>
> Possibly try testing the errorlevel returned by find...
>
> If errorlevel==1 goto :Done

Oops, perhaps this might be better...

if %errorlevel% neq 0 goto :Done

0 new messages