Posts

Showing posts from December, 2017

How to Write a Batch Program Using For Through Numbers

Image
Batch Program Using For Through Numbers. Step 1: 1.Open Notepad 2.Type your Program 3.Save your file as .bat eg. script.bat Batch Program For Through Numbers @echo off setlocal enabledelayedexpansion goto :main :main setlocal For /L %%A in (0,4,20) do echo %%A endlocal goto :eof Output: 0 4 8 12 16 20 Snaps For Reference:                               

How To write a Batch Program using For through numbers

FOR THROUGH NUMBERS Purpose: Runs a specified command for each file in a set of files. Syntax: For /L %% variable in (Start#,Step#,End#) do Command [Command Parameter] Example: @echo off For /L %%A in (0,4,20) do echo %%A In this command, we specified a start value of 0, a step value of 4, and an end value of 20. When this command is executed, the %%A variable takes the values of 0, 4, 8, 12, 16, and 20, and the Echo command is executed for each of these values. OutPut: 0 4 8 12 16 20

How to use Exit Command in Batch File

EXIT COMMAND Purpose: Quits the CMD.EXE program (command interpreter) or the current batch script. Note: Exit is an internal command if it is executed outside the batch file it close CMD.EXE Syntax: EXIT [/B] [exitCode] Prameters:   /B                specifies to exit the current batch script instead of  CMD.EXE.  If executed from outside a batch script, it  will                            quit CMD.EXE exitCode  specifies a numeric number. if /B is specified, sets  ERRORLEVEL that number. If quitting CMD.EXE, sets the                        process  exit code with that number.

How to Write Your First Batch Script Progarm

Image
First Before Writing the Program.Make sure you follow below procedures. 1.Open Notepad or any text editor  2.Next write your commands on your batch file 3.Then save your batch file as ".bat".For Example "myfirstprogram.bat " 4.Then open CMD and type file name along with your extension My First Program @echo off  Title MY First Batch File echo Hello! echo This is My First Line echo This is MY second Line OutPut : Hello! This is My first Line This is MY second Line Snap:

Command Commands Used In Batch File

Command Commands Used In Batch File Command Description Call Used to call one batch file from within another batch file without stopping the processing of the original batch file. Choice Pauses batch file processing and displays a prompt to the user to choose one of the given options using a specified key. Echo Turns the echo on or off. Also used to display a message. Endlocal Ends the localization of environment variables changed by the Setlocal command. The variables are set back to their original values. For Repeats the processing of a command for each file in a group of files. Goto Directs the batch processing to a specified line identified by a label. After jumping to the specified command line, the processing continues with the next command. If Used to perform conditional processing of commands in a batc...

How to use ENDLOCAL/SETLOCAL

ENDLOCAL/SETLOCAL ENDLOCAL: The Endlocal command ends the localization of environment variables set by the Setlocal command and restores the variables to the values they held before the Setlocal command was used. If you use the Setlocal command but forget to add the Endlocal command, the command interpreter automatically restores the environment variables to the values they held before the Setlocal command was used.This command is not effective when used outside a batch file. SETLOCAL: The Setlocal command starts the localization of environment variables in a batch file.This localization continues until a matching Endlocal command is found.You should use the Setlocal and Endlocal commands only inside a batch file. Outside a batch file or a script file, these commands have no effect. Example: @Echo off Rem This command sets local variables Rem Localization ends when Rem Processing of Mybatch2.bat file is complete Setlocal Path=%path%;C:\Myfiles;...

How to use ECHO Command

ECHO Purpose: Displays messages, or turns command-echoing on or off. Syntax:  ECHO [ON | OFF]                   ECHO [message] Prameters: [ON | OFF]:  Specifies whether to turn off or turn on the command-echoing feature. message     :  Specifies the text you want to display on the screen. Example for ECHO OFF @echo off echo echo This is my first Program echo hello echo Example for ECHO ON: C:\WINDOWS\system32>@echo on C:\WINDOWS\system32>echo this is my first program this is my first program C:\WINDOWS\system32>echo hello hello

How to use DEL/ERASE Command

DEL/ERASE Purpose: Deletes one or more files. Syntax: DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names                                  ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names Prameters:  names          Specifies a list of one or more files or directories.                        Wildcards may be used to delete multiple files. If a                        directory is specified, all files within the directory                        will be deleted.   /P                  Prompts for confirmation before deleting each file.   /F                  Force delet...

How to use DIR Command

DIR Purpose: Displays a list of files and subdirectories in a directory. Syntax: DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4] Parameters: drive:][path][filename]   Specifies drive, directory, and/or files to list.   /A              Displays files with specified attributes. attributes   D  Directories                  R  Read-only files                      H  Hidden files               A  Files ready for archiving                      S  System files                 I  Not content indexed files                 ...

How to use Chkdsk Command

Chkdsk Purpose: Checks a disk and displays a status report. Syntax: CHKDSK [volume[[path]filename]]] [/F] [/V] [/R] [/X] [/I] [/C] [/L[:size]] [/B] [/scan] [/spotfix] Prameters: volume              Specifies the drive letter (followed by a colon), mount point, or volume name. filename           FAT/FAT32 only: Specifies the files to check for fragmentation.   /F                    Fixes errors on the disk.   /V                   On FAT/FAT32: Displays the full path and name of every file on the disk.                          On NTFS: Displays cleanup messages if any.   /R                  Locates bad sectors and recovers readable information (implies /F, when /scan not specified). ...

How to Set Date Using CMD

DATE Purpose: Displays or sets the date. Syntax:   To Set Date: Date [mm-dd-yyyy] To Display Date: Date /t Prameters: mm-dd-yyyy: sets the date specified  /t: Displays the current date without prompting you for a new date. /?: Display help at command prompt. Example: Date 12-10-2017 and hit enter to set date                        

How to use Copy Command

Copy Purpose: Copies one or more files to another location. Syntax: COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/L] [/A | /B ] source [/A | /B]  [+ source [/A | /B] [+...]] [destination [/A | /B]]  source                     Specifies the file or files to be copied.   /A                           Indicates an ASCII text file.   /B                           Indicates a binary file.   /D                           Allow the destination file to be created decrypted   destination            Specifies the directory and/or filename for the new file(s).   /V                            Verifies th...

How to use CD/CHDIR Commands

CD/CHDIR Purpose: Displays the name of or changes the current directory. Syntax: CHDIR [/D] [drive:][path]                 CHDIR [..]                 CD [/D] [drive:][path]                 CD [..] Prameters: /D  change the current DRIVE in addition to changing folder.                         ..   Specifies that you want to change to the parent directory. Example:  CD                     C:\WINDOWS\system32>cd..                     C:\Windows>cd..                     C:\>cd users                     C:\Users>cd administrator   ...

how to use Call Command

Call Purpose: Calls one batch program from another. Syntax: CALL [drive:][path]filename [batch-parameters]                  CALL : label [ batch-parameters ] Example: Call D:\Folder\temp.bat

How to use Attrib Command

ATTRIB Purpose: Displays or changes file attributes. Syntax:  ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [+I | -I]  [drive:][path][filename] [/S [/D] [/L] ]          +   Sets an attribute.           -   Clears an attribute.          R   Read-only file attribute.          A   Archive file attribute.          S   System file attribute.          H   Hidden file attribute.           I   Not content indexed file attribute.          X   No scrub file attribute.          V   Integrity attribute.          [drive:][path][filename]                 Specifies a file or files for attrib to process.       ...

Assoc Command with example

Assoc Purpose :Displays or modifies the current filename extension associations. When you use this command without any parameters, it displays a list of all filename extension associations.  Syntax: ASSOC .ext = [ fileType ] Usage: ASSOC allows you to create, modify, or display associations between file extensions and file types  stored in the Windows registry. For example:  If you type assoc.txt  in cmd it will prompt  .txt=txtfile if want to change your text file into excel type assoc.txt=Excel.Sheet.8 then your file changed into excel format.For more formats type assoc and hit enter. 

Internal Command Prompt Commands

Internal commands are Ms-Dos Commands that are stored in the system memory.Here the list of Internal Command Prompt commands. Command Description Assoc Displays or modifies the current filename extension associations Call Used to call another batch program file or a procedure from within a batch file. CD (ChDir) Displays the name of the current working directory or changes the current working directory Color Changes the foreground and background colors for the current session of the command shell Cls Clears the screen of the current command shell and erases the screen buffer, resulting in a blank command prompt window. Copy Copies the specified file from one location to another. Date Displays or changes the current date on the computer. Dir Displays the contents of the current working directory, including ...