Results 1 to 6 of 6

Thread: Conditional statements in batch files

  1. #1
    Join Date
    Mar 2010
    Posts
    203

    Conditional statements in batch files

    Hello,
    I am using Microsoft Windows XP. I am trying a batch script where I can use the conditional statements in the batch script. Also, if you can explain me how the if statement works then it would be appreciated. I have studied the if statement but any more information on the same will add to my knowledge. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    356

    Re: Conditional statements in batch files

    Hello,
    Check out the following script
    Code:
    @echo off
    set cnt=0
    for %%v in (2007_088.h20v08.hdf 2007_088.h20v09.hdf 2007_088.h20v10.hdf 2007_088.h21v08.hdf 2007_088.h21v09.hdf 2007_088.h21v10.hdf 2007_088.h22v08.hdf 2007_088.h22v09.hdf 2007_088.h22v10.hdf) do (
    	if exist %%v call set /a cnt=%%cnt%%+1
    	)
    if cnt  9 goto :eof
    .
    . put your code here
    .
    .
    .
    Add your code to the end of this script.

  3. #3
    Join Date
    Nov 2009
    Posts
    335

    Re: Conditional statements in batch files

    Hello,
    Here are some of the syntax which are used in the batch file for the conditional statements
    Here is the list
    Code:
    - IF [NOT] 
    - IF [NOT] string1==string2 
    - IF [NOT] EXIST 
    - NOT 	
    - number    	
    - command 
    - string1==string2
    - EXIST
    I hope this will help you.

  4. #4
    Join Date
    Nov 2009
    Posts
    518

    Re: Conditional statements in batch files

    Hello,
    The following script will compare the two strings using the conditional statement used in the script
    Take a look at the following code
    Code:
    echo off
    bcc32 %1.c > temp.txt
    GOTO result%temporlevel%
    :result1
    IF %2==default (notepad.exe temp.txt) ELSE (%2 temp.txt)
    GOTO end
    :result0
    %1
    :end

  5. #5
    Join Date
    Nov 2009
    Posts
    343

    Re: Conditional statements in batch files

    Hello,
    If you need to study the errors which are possible in the batch file which using the conditional statements, then you can see the below example
    Code:
    echo off
    bcc32 %1.c > temp.txt
    IF %temlvl% 1 (notepad temp.txt) ELSE %1
    The above code will generate an error, so now you can see the error and study it. I think this will help you. If you have any more queries regarding this the you post back.

  6. #6
    Join Date
    Nov 2009
    Posts
    347

    Re: Conditional statements in batch files

    Hello,
    I have a code with me, see if this code helps it
    Code:
    @echo off
    set /a cntr=0
    :numbers
    set /a cntr=%cntr%+1
    if %cntr% ==100 (goto :eof) else (echo %cntr% >> E:\count.txt)
    goto :numbers
    The conditional statements here is explained very well here.

Similar Threads

  1. Cool Batch Files
    By Muwafaq in forum Tips & Tweaks
    Replies: 13
    Last Post: 11-08-2011, 05:18 PM
  2. Conditional statements in C sharp
    By Vaikuntam in forum Software Development
    Replies: 3
    Last Post: 16-12-2010, 08:36 AM
  3. Difference between DML statements and DDL statements
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 11-01-2010, 01:07 PM
  4. How to convert batch files
    By SoftwareGuy in forum Tips & Tweaks
    Replies: 1
    Last Post: 03-04-2009, 05:26 PM
  5. Can we Write conditional statements in CSS?
    By machok in forum Software Development
    Replies: 3
    Last Post: 04-03-2009, 01:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,932,678.48403 seconds with 16 queries