What are Batch files in Windows?

Batch files in Windows are the script files. A batch file is an unformatted text file. This file consists of a series of commands and has a .bat or .cmd file name extension. The term “batch” is adapted from batch processing – which means non-interactive execution. With batch files in Windows, users can simplify repetitive or routine tasks. When users type the file name at the command prompt, cmd.exe runs the commands sequentially, as they appear in the file. Some typical commands used in the batch files in Windows are – Call, Echo, Endlocal, For, Goto, If, Pause, Rem, Setlocal, and Shift.

How to create .bat or batch files in Windows

As mentioned earlier, a batch file contains a series of DOS commands and are used to automate the frequently performed tasks. Thus, you don’t have to repeatedly write the same commands.

A batch file is created using a Notepad. The text file consists of the commands you want to execute.  To create a Batch file, you have to write the command as text in Notepad, and save the file as a .bat file. To execute a command, you simply need to double-click the batch file. Hence, a well-written batch file in Windows can save a lot of time.

Some basic Commands in Batch Files:

  • ECHO: To display the text on the screen
  • @ECHO OFF: To hide the text
  • START: To run a file with its default application
  • REM: To enter a comment line in the program
  • MKDIR: To create directories
  • RMDIR: To remove directories
  • DEL: To delete files
  • COPY: To copy a file or files
  • XCOPY: To copy files with extra options
  • FOR/IN/DO: To specify files
  • TITLE: To edit the title of the window

 

Hide Drive/Partition using CMD (Command Prompt)

Hide Drive using CMD

1] Open an elevated command prompt, type Diskpart and hit Enter.

2] Type List Volume and hit Enter.

3] Now type select and the numeral against the letter of the Drive (e.g.,. it could be G Drive), which you want to hide. For instance, it could be Select Volume 6. Hit Enter.

4] Finally, type Remove Letter G and hit Enter.

You will see a message – Diskpart successfully removed the drive letter or mount point.

To show the hidden drive, follow steps 1, 2, 3 mentioned above.

Now type Assign Letter D and hit Enter. This will show the drive in Explorer.