Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Need to Parameterise Batch File  (Read 2750 times)

0 Members and 1 Guest are viewing this topic.

rajeshp

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    Need to Parameterise Batch File
    « on: January 28, 2016, 06:33:47 AM »
    Hi I have created a batch file. And using some parameters in batch file I am Reading parameter value from my notepad file.
    Other-way around I have create a notepad file with name test.txt which include
    Monday, April, 01
    Tuesday, Nov, 08
    Friday, Jan, 31
    I have created a batch file which in which I will use this values as argument.
    My Batch file is something like:
    @echo off
    set Day =  FOR /F "tokens=1 delims=," %G IN (D:\Framewok\test.txt) DO @echo %G
    set Month = %FOR /F "tokens=2," %G IN (D:\Framewok\test.txt) DO @echo %G
    set Date = %FOR /F "tokens=3," %G IN (D:\Framewok\test.txt) DO @echo %G
    echo
    echo Day is %Day%
    echo Month is %Month%
    echo date equals %Date%
    pause

    Here I am not able to pull any value from text file. Also do let me know if I want only some value in next row i.e. Tuesday  Or  Jan Or 01 only from notepad how to do this.
    Can anyone let me know.

    Thank you in Advance,

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Need to Parameterise Batch File
    « Reply #1 on: January 28, 2016, 11:28:29 AM »
    You must come from the BASH scripting world.
    Code: [Select]
    @echo off
    FOR /F "tokens=1-3 delims=," %%G IN (D:\Framewok\test.txt) DO (
         set Day=%%G
         set Month=%%H
         set Date=%%I
         setlocal enabledelayedexpansion
         echo.
         echo Day is !Day!
         echo Month is !Month!
         echo date equals !Date!
         endlocal
    )

    pause
    « Last Edit: January 28, 2016, 11:47:41 AM by Squashman »