In this article, Mytour will guide you through the process of writing and saving a basic batch file on a Windows-operated computer. A batch file contains a series of DOS commands (Windows language) and is typically created to automate routine tasks such as file transfers. You won’t need any advanced compiling software to create a batch file; the standard Windows Notepad program is more than sufficient.
Steps
Learn the basics of batch files
Launch Notepad.Begin
NotepadNotepad- Notepad is commonly used to convert text documents into batch files. However, you can write the text portion of a batch file almost anywhere.

- ECHO – Displays text on the screen
- @ECHO OFF - Hides text that is usually displayed
- START – Runs a file using its default application
- REM – Inserts a comment line into the program
- MKDIR/RMDIR – Creates and removes directories
- DEL – Deletes files
- COPY – Copies files
- XCOPY – Allows file copying with additional options
- FOR/IN/DO – This command lets you specify files
- TITLE – Edits the window's title

MKDIR c:\example1 MKDIR c:\example2

@ECHO OFF XCOPY c:\original c:\backupfolder /m /e /y
- These commands will copy files from the "original" folder to the "backupfolder". You can replace the paths with the directories you prefer. /m ensures only updated files are copied, /e specifies that all subdirectories within the listed folder will be copied, and /y confirms that overwrite prompts will be suppressed for all files.

@ECHO OFF cd c:\source REM This is the location of the files you want to organize FOR %%f IN (*.doc *.txt) DO XCOPY c:\source\"%%f" c:\text /m /y REM This command moves all .doc or .txt files from c:\source to c:\text REM %%f is a variable FOR %%f IN (*.jpg *.png *.bmp) DO XCOPY C:\source\"%%f" c:\images /m /y REM The above command moves all .jpg, .png, and .bmp files from c:\source to c:\images

Save the batch file

Complete the text content of the batch file. Once you've entered and reviewed everything, you can proceed to save it as an executable file.

Click on File. This button is located in the top-left corner of the Notepad window. A dropdown menu will appear.

Select Save As… from the File dropdown menu. The Save As window will open.

Enter the file name with the ".bat" extension. In the "File name" text box, type the name you want for your program and end it with .bat.
- For example, to create a program named "Backup", you would type Backup.bat.

Click on the "Save as type" dropdown box. This box is located near the bottom of the Save As window. A new dropdown menu will appear.

Click on All Files in the dropdown menu. This allows you to save the file in any format (in this case, ".bat").

Choose the save location. To do this, click on the desired folder from the list on the left side of the window (e.g., Desktop – save to the desktop).

Click Save. This option is located in the bottom-right corner of the Save As window. The window will close.

Close your Notepad file. The file will be saved as a batch file in the folder you selected.

Edit the batch file content. You can right-click the batch file and select Edit from the dropdown menu at any time. The batch file will open as a Notepad document, allowing you to make changes and save the file by pressing Ctrl+S.
- Changes will be reflected the next time you run the batch file.
Tips
- Use quotation marks to open folders or files with names containing spaces (e.g., start "C:\Documents and Settings\").
- Third-party editors like Notepad++ can be used to edit batch files. However, for simple batch files, this is generally unnecessary.
- Some commands (e.g., ipconfig) require administrator privileges to run. If you're using an admin account, right-click the file and select "Run as Administrator".
Warnings
- Depending on the commands used, batch files can pose risks. Ensure the code you use does not execute unintended actions (e.g., deleting files or damaging the computer).
