Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using fc with batch file

Posted on 2007-12-05
12
Medium Priority
?
1,992 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 2000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 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