Results 1 to 3 of 3

Thread: How to Write a Batch File ?

  1. #1
    Join Date
    Feb 2009
    Posts
    78

    How to Write a Batch File ?

    hello friends,

    I need to write a batch file, but I am completely unaware of how to start with it. Can anybody please help me providing information on how to write a batch file ?

    thanks a lot....

  2. #2
    Join Date
    Apr 2008
    Posts
    3,522

    Re: How to Write a Batch File ?

    Follow the instructions below to Write a Batch File :-

    • Open NotePad > go to File > select Save As > choose a file name > select desktop as a location to save afile but don't click Save yet…
    • Click on the dropdown menu next to "File name" and select "All files" instead of “.txt”
    • Before you save , add .bat to the end of your file name. For example, you would type example.bat.
    • Click on Save.
    • A file name in the title of Windows Notepad should appear. Make sure that it reads as example.bat—not example.bat.txt.


    Now you are ready to create your batch file.

    • Type "@echo off" on the first line of your batch file. This will prevent any spaces in the batch file to be read by the program when executed.

    • Enter your commands. The following example will show you how to create a batch file that will automatically load wikiHow.com using Internet Explorer.
      • @echo off.
      • REM The following will open website.com in a new Internet Explorer window.
      • "start Iexplore.exe www.website.com"
      • REM The following will open website.com in your default browser, but if it is IE and you have another IE window open, then it will hijack that window.
      • "start www.website.com"


    • Save the file by "File > Save" and type in "website.bat".

    • Run the file by double clicking the file on your desktop.



    source - http://www.wikihow.com/Write-a-Batch-File

  3. #3
    Join Date
    May 2008
    Posts
    2,680

    Re: How to Write a Batch File ?

    To create a basic batch file in MS-DOS, follow the steps below --

    Open an MS-DOS command window.
    At the MS-DOS prompt, type: edit test.bat and press enter.
    A blue screen should appear. Within the screen, type:
    pause
    dir c:\windows
    dir c:\windows\system


    Click File and choose Exit.

    When prompted to save, click "Yes." Users who do not have a mouse cursor can accomplish this same task by pressing ALT+F to access the file menu, then pressing "X" to exit, and pressing enter to save changes.

    Once you are back at the MS-DOS prompt, type: test and press enter. This will execute the test.bat file and begin running the file. Because the first line is pause, you will first be prompted to press a key. Once you press a key the batch file will run line-by-line; in this case, listing the files in the windows and windows\system directories.

    A Windows user can still use the above MS-DOS steps if they wish to create a batch file. If, however, you're more comfortable using Microsoft Windows or your operating system, you can use any text editor, such as Notepad or Wordpad, to create your batch files, as long as the file extension ends with .bat. In the below example we use the Windows notepad to create a batch file.

    Click Start -- Click Run -- Type: notepad -- press Enter.

    Once notepad is open, type the below lines in the file or copy and paste the below lines into notepad.
    @echo off
    echo Hello this is a test batch file
    pause
    dir c:\windows


    Click File -- Save and browse at the location where you want to save the file.

    For the filename, type "test.bat" and if your Windows version has a "Save as type" option, choose "All files". Otherwise it will save a file as a text file. Once everything is done, click on Save button and exit Notepad.

    Now, simply double-click or run the file like any other program for running a batch file. Once a batch file has completed running, it will close the Window automatically.


    source - http://www.wikihow.com/Write-Batch-Files

Similar Threads

  1. make file name list in excel using batch file
    By shibinpanayi in forum Windows Software
    Replies: 1
    Last Post: 04-06-2011, 03:44 AM
  2. Learning Batch file to open a program or a file
    By Ikshana in forum Windows Software
    Replies: 3
    Last Post: 04-04-2011, 07:24 PM
  3. Windows Batch file to output directory names and size to txt file
    By m2thearkus in forum Software Development
    Replies: 6
    Last Post: 16-07-2010, 12:04 AM
  4. Dos batch file to sort files based on file names.
    By Jon Osborn in forum Windows Server Help
    Replies: 9
    Last Post: 17-06-2009, 11:06 AM
  5. Replies: 3
    Last Post: 12-03-2009, 12:56 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,714,284,552.77392 seconds with 17 queries