Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
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%.txtI 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! :)

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
HTH
M2

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 adressI'll try to show what i want:
If "string" found in %variable% goto nextWhen 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 "

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
:different
They are fifferent; so we're here:end
M2

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

@echo off
echo %var% | find "string"if errorlevel 1 goto :not-found
:found
::Do found stuff
goto :end:not-found
::Do not found stuff:end
M2

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

SchrOOm,
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
HTH
M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |