Solved

using fc with batch file

Posted on 2007-12-05
12
1,961 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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
 

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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

730 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