In this blog post, I will describe how to create a batch file to copy files from one folder to another folder. A batch file is a text file that contains a sequence of commands for a computer operating system.
The batch script file has a bundle or package of a set of commands that is the reason it is called the batch file. The extension of the bat script file is .bat or .cmd.
If you are new in batch scripting and want to learn how to create the batch file, you can see the below article
Now let us come on the topic to see how we can copy the file from one folder to another using the batch file.
There are many batch file commands available to copy files from one folder to another folder. In the below example, I am using the copy command to move the file from one folder to another folder.
Mainly there are two steps to copy files from one folder to another folder using batch script.
1) Creating the batch file:
- Open the notepad or notepad++ and create the new file.
- Now save the newly created file with .bat extension.
After saving with .bat extension newly created file becomes a bat file.
2) Write the script in the batch file
After creating the batch file, you can write the script to copy files from one folder to another folder. Below I have written a script which will ask the file name and copy the files from the folder ” D:\amlendra\docs” to folder “D:\amlendra\data”.
You can change the folder according to your use. So let us see the batch script.
@ECHO OFF REM change console screen COLOR F0 REM source folder location set Source_Folder=D:\amlendra\docs REM destination folder location set Dest_Folder=D:\amlendra\data REM Ask file name from user set /p FileName= Enter File Name REM if destination folder not available, create mkdir %Dest_Folder% REM copy the files copy %Source_Folder%\*%FileName%* %Dest_Folder%\.
Output: