How to create and use Batch file
The batch file runs pre-defined DOS commands when it executes. We don’t need to write DOS commands every time. We just write all commands in notepad and save them as a batch file. When the batch file executes, it runs all DOS commands one by one.
So we will create a batch file to copy a file from one location to another location.
Step 1: Create two folders in C: drive as “Source Folder” & “Destination Folder“
Step 2: Create an excel file in this folder and rename it to “testcopy”. You can create any other type of file and can give any other name you like. It is just for example.
Step 3: Open Notepad in your system.
Step 4: Write the below code in Notepad:
'This command will copy testcopy excel files from source to destination folder
Copy "C:\Source Folder\testcopy.xlsb" "C:\Destination Folder"
Step 5: Go to the File menu and click on Save or press Ctrl+S.
Step 6: Give any name to file and write .bat in last then Save. For example Copy.bat
Step 7: Now double-click on the batch file or right-click and then choose the option to run. It will execute in the command prompt DOS window and will copy “testcopy.xlsb” file.
Note:- If you want to edit the batch file, then right-click on it and then click on Edit or you can open the batch file in Notepad and after editing you can save it.
*** Copy all Excel files using batch command ***
It is very easy to copy all excel files from Source Folder to Destination Folder.
Just write the below code or change testcopy to * :
Copy "C:\Source Folder\*.xlsb" "C:\Destination Folder"
*** Copy all files using batch command ***
Replace the excel file extension .xlsb with * and it will copy all files from Source Folder to Destination Folder.
Just write the below code or change xlsb to * :
Copy "C:\Source Folder\*.*" "C:\Destination Folder"