The batch script, also known as batch file, actually refers to a list of several commands; whenever you double-click the file, the commands will be executed. If you want to copy files or folders from one folder to another automatically, creating a batch script is a nice choice. As for how to get the work done, please keep reading.
Windows Script/Batch File
When managing your data on PC, you may need to copy or move files and folders. The permissions set on files and folders may be changed when you move/copy them by using the Windows Explorer. Did you know this?
For instance, when you copy a folder/file in an NTFS partition or from one partition to another, the Windows system will regard it as the new folder/file; in this way, you will become the CREATOR OWNER since the system will take on the permissions. That’s why using script to copy files from one folder to another is necessary.
What Is Batch File
A batch file, also known as batch script, is actually a list of commands that will be run in the Command Prompt (CMD) tool. Users can create a batch file to let CMD copy and paste files for them automatically; all they need to do is double clicking on the batch file/script and waiting.
Can You Use Script to Copy Files from One Folder to Another
The Windows clipboard provides an easy way for users to copy and paste files/folder manually. The ordinary copy process seems pretty simple: select the file/folder that needs to be copied and choose copy option; open the destination; select the paste option.
Yet, do you want to automatically move files from one folder to another? The copying and pasting process can be finished quickly by using the Windows command line.
How to create batch file to copy files? How to use Windows script to copy files? Generally, it contains two stages: create batch file and create a task to run the batch file to copy files from one folder to another.
Stage One: Create Batch File to Copy
You can create a batch file to copy data in a file from one place to another place on your computer automatically. The following steps are finished on Windows 10.
- Open Windows search.
- Type notepad.
- Open the Notepad app.
- Copy & paste the script into the new Notepad file.
- Select File -> Save As.
- Give it a name.
- Select All Files.
- Click Save to finish creating the batch file.
Step one: click on the Cortana icon on the taskbar (fix taskbar not working on Window 10).
Step two: type notepad into the search text box.
Step three: select Notepad app from the search result by clicking on it.
Step four: type the following script in or copy & paste it into Notepad.
set "source=C:\<Source Folder Path>"
set "destination=D:\<Destination Folder Path>"
robocopy "source" "destination" "filename with extension" /z
- The source folder, destination folder, and number of days can be changed due to your needs.
- The nunber of days refers to the time interval you want to archive your folders.
- "<>" is necessary if the source or desitination folder path includes space.
Step five: choose File option from the menu bar and choose Save As… from submenu.
- Give it a name and type in the File name text box; the file name format is <filename>.BAT.
- Select All Files for Save as type option to change the default file type.
- Click on the Save button at the bottom to finish this step.
Stage Two: Create Task to Run Batch File
After finish this stage, you can use the batch file to copy folder to another location.
Step one: type task scheduler into the Cortana search box.
Step two: choose Task Scheduler from the search result.
Step three: find Actions section from the right-hand panel.
Step four: select Create Task… from the list.
Step five: give a name for the task and type it into the text box after Name.
Step six: shift to Triggers tab and click on the New… button.
Step seven: define the frequency to trigger the task, choosing from One time, Daily, Weekly, and Monthly.
Step eight: set the Start time to decide when the task will be triggered and click on the OK button to confirm.
Step nine: shift to Actions tab and click on the New… button.
Step ten: click on the Browse button to find & choose the .BAT file you have created in stage one.
Step eleven: click on the OK button to confirm. Then, you can close the Task Scheduler and start to move file from one folder to another by using it.
That’s how to use Windows batch to copy file. Besides, you can also use Xcopy or Robocopy to copy files and folders on your PC.