Solved

using fc with batch file

Posted on 2007-12-05
12
1,978 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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

623 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