How to Move Files Using Batch Script

MD Aminul Islam Feb 02, 2024
How to Move Files Using Batch Script

This tutorial will see how we can move a file using Batch Script.

Use Batch Script to Move Files

We can move a file from one destination to another by dragging the file from the source and dropping the file in the targeted location. We can also perform the task by simply right-clicking the file and clicking on cut, then paste it to the targeted destination.

There is another way to do a similar task programmatically. We will create a batch script that will move files from one destination to another.

For this purpose, we’ll use a built-in Batch script command called MOVE.

Syntax:

MOVE [OPTIONS] [SOURCE DESTINATION] [TARGETED DESTINATION]

Below are the available options for this command.

  • /Y - Suppress confirmation prompt when files are overwriting.
  • /-Y - Enable confirmation prompt when files are overwriting.

Command Script:

MOVE "C:\SOURCE\TestFile.txt" "C:\DESTINATION\"

In the above example, we are moving the file named TestFile.txt from one destination to another, but this is for a single file. Let’s look at the following example code.

Command Script:

MOVE "C:\SOURCE\*.*" "E:\DESTINATION"

The above example will move all the files from the SOURCE folder to the DESTINATION folder. You can use the option that we already discussed above to let the system notify you if any overwriting occurs.

The code *.* means a file with any name or type will be moved to the destination folder. We are not using any file filter for the command.

This command can generate the following error levels.

  • %ERRORLEVEL% = 0 - Generates if the file successfully moved.
  • %ERRORLEVEL% = 1 - Generates if there are wrong parameters provided, couldn’t be moved, or file not found.
MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn

Related Article - Batch Command