Solved

using fc with batch file

Posted on 2007-12-05
12
1,918 Views
Last Modified: 2010-04-21
i have 2 text files called existing.txt and new.txt.  each holds a program version number.

i want to check these files before copying in a new version (ie. if they are the same no copy is needed).  if the version of new < version of existing i don't want to copy in.  i only want new versions greater than existing versions.

i created a vbscript file to give me the version which i send the output to a file.  but the file contains a blank line, then the version number.

how do i compare these two files within a batch the way i need to?
0
Comment
Question by:Fraser_Admin
  • 7
  • 5
12 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
ID: 20414267
Depends on how the version information is formatted in the output files you mentioned.

You could do something like this. You'd format the names of the files as the 2nd parameter to the GETVER calls.
@echo off
 

setlocal
 

call :GETVER oldVer "oldver.txt"

call :GETVER newVer "newver.txt"
 

if /i "%oldVer%" GTR "%newVer%" echo Old version is newer than old version
 

goto :EOF
 

:GETVER
 

set %~1=
 

for /f "tokens=*" %%a in ('type "%~2" 2^>NUL') do set %~1=%%a
 

goto :EOF

Open in new window

0
 

Author Comment

by:Fraser_Admin
ID: 20414571
the text file begins with a blank line then the version will be like
1.1.3 or something like that.

how do i compare if they are equal?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20414585
Replace line 8 with this:

if /i "%oldVer%" EQU"%newVer%" echo Old version is equal to the old version

Check this for more information on the if command:

if /?
0
 

Author Comment

by:Fraser_Admin
ID: 20414732
how do i set a return value in batch

if it is equal or if old > new than I want to return 1 otherwise i want to return 0.

i need to be able to access this value in another batch file.  i just want to call this as a separate one.
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20414826
if /i "%oldVer%" GTR "%newVer%" exit /B 1

exit /B 0
0
 

Author Comment

by:Fraser_Admin
ID: 20414857
but how do i access that return value in my calling batch.

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Fraser_Admin
ID: 20414956
also, when i call
exit /B 1
for example, i can't see to get past that in my calling batch.  i put in some echos after that and nothing appears.

i need to be able to get that value of 1 in my calling batch.  i think i can do this with errorlevel right?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20414983
That's right. You answered your own question. Once the batch processing hits a exit, the batch is exited as the command says. You'd test %errorlevel% in your calling batch processing to determine the results.
0
 

Author Comment

by:Fraser_Admin
ID: 20415038
i can't seem to get passed my call to the batch.  i put in an echo as soon as i exit from the batch but it does not come up.
I have this in my called batch
exit /B 1

then in the calling batch right after i have the call to this batch i have echo done and it doesn't get there.  it is like that exit call is telling it to exit from the called and calling batches.
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 20415080
Are you calling the batch file using call?

call yourbatch.bat

If not you won't return.
0
 

Author Comment

by:Fraser_Admin
ID: 20415319
no just figured that out.  thanks so much for your help!!!
0
 

Author Closing Comment

by:Fraser_Admin
ID: 31412939
Excellent Response!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now