Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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 foundUnderstood? 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=VALUETo use a variable:
%VARIABLE%To check a variable (compare with something):
if "%var%"=="abc" goto beginIn 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

![]() |
![]() |
![]() |

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