Find string inside a variable,batch

January 17, 2005 at 17:16:10
Specs: Win Xp Pro, Amd 3200,1Gb

here's what i could need some help with..
1. I want to read a whole txt document into a variable. Also it would be nice to check if a certain word inside the variable exist so i could compare two variables with the if command.

2. I would like to compare 2 files, and use a if command to do some action if they are alike/not alike

3. I would like this to work, but it doesnt:
echo echo File %wheretoo0%\%wheretoo1%%choise1% already exist, skipping file >> ErrorLog.txt >>%filename%.txt

I have a main batch that generates a new file with its own script.
I want to echo >>errorlog.txt into filename.txt, but it doesnt seems to work when using >>errorlog.txt>>filename.txt
The filename.txt is supposed to check if a filename exist and then echo "File doesnt exist" into a errorlog if file doesnt exist.

Ok.. Its kinda late, so i dont know if any of this is understandable..

Hope anyone can help me! :)

See More: Find string inside a variable,batch

Report •

January 17, 2005 at 19:35:15

Hi Schroom,

Sounds like it was kinda late.

First, You will not be able to set a variable as a whole text file unless the file is quite small; you'll soon be out of environment.

You can do compares with FC

if exist filename.ext echo msg1 >> my.log



Report •

January 18, 2005 at 06:54:21

Hehe.. It was late ye..

Well, i dont want a big txt file to be read.
max 3lines would do just fine.
I would then like to search for a string inside the variable containing the text.
For example an ip adress

I'll try to show what i want:
If "string" found in %variable% goto next

When it comes to file comparing, i'll illustrate what i was thinking aswell:

If file1=file2 goto next

I dont know if this is possible tho, or if i have to use fc file1 file2>>result.txt
,then read result into a variable and then look for a string inside the variable.

Hope that made more sense..

And finally, hope anyone can help me with the last one (nr.3).

Problem is that i cant echo this into the file called filename.txt
"echo File %wheretoo0%\%wheretoo1%%choise1% already exist, skipping file >> ErrorLog.txt "

Report •

January 18, 2005 at 07:51:38

That makes more sense.

One piece at a time.

For a file compare:

fc file1 file2
if errorlevel 1 goto :different

::Here's where we do what we do when they are the same

goto :end

They are fifferent; so we're here



Report •

Related Solutions

January 18, 2005 at 10:18:18

Ahh.. Works perfectly! Thnx:)

Is it by any chance you would know how i can solve the problem with searching for a string inside a variable? (or any website you could refer too)

If "string" in variable found goto :found

Report •

January 18, 2005 at 10:31:17

@echo off
echo %var% | find "string"

if errorlevel 1 goto :not-found

::Do found stuff
goto :end

::Do not found stuff



Report •

January 18, 2005 at 10:50:22

Thnx once again:) You have been a big help to me. I'll have abit more look into the use of errorlevels..

Report •

January 18, 2005 at 10:59:30


One thing to whatch out for is that the:

if errorlevel x

test evaluates true if the errorlevel is equal to **OR MORE THAN** x



Report •

Ask Question