Writing Your Own Batch File


Writing Your Own Batch File

  1. 1
    Open Notepad in Windows. Notepad will allow you to create a file without unnecessary coding. You can do this by navigating to Start -> Programs -> Accessories -> Notepad.
  2. 2
    Save your file before you get started. This will prevent your work from being a totally lost later.
    • Click File -> Save, and choose a file name.
    • Save the file somewhere on the Desktop.
    • Click the dropdown menu under "Save as type" and select "All files" instead of Text (.txt).
    • Add the extension .bat to the end of the file name. For instance, you might save a test file called "test.bat".
    • Click Save. If you did this correctly, you should see your file name in the title bar of Notepad.
  3. 3
    Type @echo off into the first line of your batch file. This will stop several lines of repetitive output from showing up in your command screen when you execute the batch file.
    • Observe the operation of the REM, or Remark, command. REM provides a way to comment on one or more commands or the operation of the whole batch file for documentation purposes. We'll use REM in the following example.

      #Type an example program. This batch file automatically loads Internet Explorer and opens wikiHow's homepage. Type the following into the Notepad window:
    • @echo off.
    • REM Next command will open wikihow.com in a new Internet Explorer window.
    • start /d "C:\Program Files\Internet Explorer" explorer.exe www.wikihow.com
    • @echo off.
    • REM Next command will open wikihow.com in a default browser.
    • start www.wikihow.com
  4. 4
    Save and run the file by double-clicking test.bat on your Desktop.
  5. 5
    Insert variables (optional). Variables can also be inserted into batch structure using command line arguments in the form of %1, %2, etc. Here's a sample that will copy a file from Folder1 to Folder2.
    • @echo off.
    • Type in 'set 1=C:\folder2'; hit <enter>, then type 'COPY C:\folder1\data.xls %1%\data.xls'
    • Save as cpy.bat and run the file by double-clicking it on your Desktop.
    • Alternatively, you can run it from the command prompt:
    • Type in 'set 1=C:\folder2'; hit <enter>, then type 'COPY C:\folder1\data.xls %1%\data.xls'



--
Regards :
Vikram Singh Rana
Computer Science Engineer
9983384690

Comments

Popular posts from this blog

Generate a Report using Crystal Reports in Visual Studio 2010

SQL Server Database is enabled for Database Mirroring, but the database lacks quorum, and cannot be opened – Error 955

40 Cool Kitchen Gadgets For Food Lovers. I’d Love To Have #14!