Computing.Net > Forums > Disk Operating System > Passing Variable to Batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Passing Variable to Batch

Reply to Message Icon

Name: Tony Smith
Date: March 22, 2002 at 16:01:36 Pacific
Comment:

I want to add a couple of lines to my batch files that move files from one directory to another.

I want to use FIND or FINDSTR to search the file it is moving for the character "*" (Asterisk).
If the test is true, I want to set a variable to "1" else "0"

Then I want to use IF to test the variable and branch off to do something
different (Rename file) if the variable is equal to "1"

One thing I can't figure out is how to create the variable in the first
place.

Can you help?

The problem is, I can't find the state of the find or findstr to pass to SET... look at this...

@ECHO OFF
REM BMA810.bat
REM This prepares the BMA 810 export files for processing
REM and safeguards them from conflicting with user input
-----------------
Rem This checks for asterisks
-----------------


FINDSTR /LMC:"*" V:\EData\OrdX25-A\BMA\Ansi\810\4010\ABM81091.rfm

(Get the state and set variable) SET FF=1 .... blah blah

IF FF=1 GOTO FOUND

-----------------
REM This moves file
-----------------
Move V:\EData\OrdX25-A\BMA\Ansi\810\4010\*.* U:\EData\OrdX25-A\BMA\Ansi\810\4010\
u:
CD U:\EData\OrdX25-A\BMA\Ansi\810\4010\
---------
REM This renames the file
---------
@ECHO ON
Rename ABM81091.rfm BM81091.rfm
@ECHO OFF
---------
REM This writes export file to mail_out.rfm
---------
@ECHO ON
TYPE BM81091.rfm >> mail_out.rfm
@ECHO OFF
GOTO END


:FOUND
---------
REM THIS MOVES THE FILE CONTAINING ASTERISKS
Move V:\EData\OrdX25-A\BMA\Ansi\810\4010\ABM81091.rfm V:\EData\OrdX25-A\BMA\Ansi\810\4010\CORRUPT\

:END



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: March 22, 2002 at 17:56:01 Pacific
Reply:

Hi. I don't know how to work with FINDSTR (I'm on Win98, you're on NT, right?). But I think we can do this using FIND:

FIND "*" file.dat > nul
if errorlevel=1 goto notfound
if not errorlevel=1 goto found

Understood? FINDSTR will likely also emit an errorlevel 1 if it doesn't find the string, so you may use it as above.

BTW, to set a variable:
SET VARIABLE=VALUE

To use a variable:
%VARIABLE%

To check a variable (compare with something):
if "%var%"=="abc" goto begin

In the above case, if the variable %var% is equal to abc it will 'goto begin'. The quotes aren't necessary, but there must be something on both sides:

if "%var%=="abc ...
if (%var%)==(abc) ...
if %var%!==abc! ...

NEVER use:
if %var%==abc ...

That's because the %var% value may be empty, so the statement will return an error message, since there's nothing on the left side of the "=="

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Passing Variable to Batch

passing variable between batch file www.computing.net/answers/dos/passing-variable-between-batch-file/13921.html

passing param to batch from HREF www.computing.net/answers/dos/passing-param-to-batch-from-href/14323.html

passing parameters to batch? www.computing.net/answers/dos/passing-parameters-to-batch/14305.html