move - Move files and folders

Maintained on
Table of Contents

Moving specific files or folders to another location is a common task when working with the command prompt.

On this page, we cover the move command prompt and batch files, which are often used to manipulate folders on a PC. We explain how to delete files, from basic usage to setting options, in an easy-to-understand way. We also provide specific sample code.

What is the move command?

The move command allows you to move specified files or folders to another location.

The basic usage of the move command is as follows:

move <file or folder to be moved> <destination file or folder>

The most basic usage of the move command is to specify the file or folder to be moved and the destination file or folder, as shown above. However, more detailed usage is available as follows.

move [{/y|/-y}] <file or folder to be moved> <destination file or folder>

By using the /y option, you can control whether or not to display a message when a file already exists in the destination folder.

When /y is specified, the confirmation message for overwriting files will not be displayed, even if the file already exists.

By default, a confirmation message is displayed, but even if you specify /-y, the confirmation message for overwriting files will still be displayed.

The default behavior can be changed by the COPYCMD environment variable, but /y and /-y given on the command line always take precedence. You can also use wildcards (such as *.txt) to move multiple files at once.

By default, no overwrite prompt appears inside batch files

The overwrite confirmation is the default behavior when you run the command directly from the Command Prompt. When move runs inside a batch file, it overwrites without asking by default, as if /y were specified. Specify /-y explicitly if you want the confirmation.

Examples of the move command

To move a file named test.txt that exists in the current directory to the folder C:\test, use the following command:

move test.txt C:\test

When you run the above code, the following output is displayed:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move test.txt c:\test
1 file(s) moved.
C:\users\user>

In the above example, since there is no file named test.txt in the destination folder c:\test, the move is completed and the process ends.

If there is a file with the same name test.txt in the destination folder, the following output is displayed:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move test.txt c:\test
Do you want to overwrite c:\test\test.txt? (Yes/No/All):

If you enter No, the file will not be moved and the following output will be displayed:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move test.txt c:\test
Do you want to overwrite c:\test\test.txt? (Yes/No/All): No
0 file(s) moved.
C:\users\user>

If you enter Yes or All, the file will be moved and the following output will be displayed:

If you are moving multiple files at once with a wildcard such as *.txt and enter All, the confirmation message will not be displayed for the remaining files.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move test.txt c:\test
Do you want to overwrite c:\test\test.txt? (Yes/No/All): Yes
1 file(s) moved.
C:\users\user>

/y option

In the previous example, a confirmation message was displayed when a file with the same name existed in the destination folder.

By specifying the /y option, you can overwrite without displaying a confirmation message.

Regardless of whether or not there is a file with the same name in the destination folder, no confirmation message is displayed and the following output is displayed:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move /y test.txt c:\test
1 file(s) moved.
C:\users\user>

Moving folders

If you select a folder as the target to move, all files in the folder will also be moved.

Assume that there is a sample folder with the following structure:

└─sample
        sample01.txt
        sample02.txt
        sample03.txt
        sample04.txt

To move the sample folder to the C:\test folder, use the following command:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move sample c:\test
1 directory moved.
C:\users\user>

After execution, the C:\test folder will have the following structure:

C:\test
│
└─sample
        sample01.txt
        sample02.txt
        sample03.txt
        sample04.txt
A nonexistent destination folder is treated as a file name

If you move a file with a command such as move test.txt C:\newdir and newdir does not exist, test.txt is moved as a file named newdir. To make sure the destination is treated as a folder, create it beforehand with mkdir. Adding a trailing \, as in move test.txt C:\newdir\, makes the command fail with an error if the folder does not exist, which prevents moving under an unintended file name.

Folders cannot be moved to another drive

The move command can only move folders within the same drive. To move a folder from C: to D:, copy it with xcopy or robocopy and then delete the original. Files can be moved across drives.

Renaming with the move command

In the previous examples, we did not specify the file name of the destination.

If you do not specify a file name, the file name of the source will be used as the file name of the destination.

To change the file name of the source and destination, use the following command:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move test.txt c:\test\sample.txt
1 file(s) moved.
C:\users\user>

The same applies to folders. If you specify a non-existent folder, the folder name of the source will be used as the folder name of the destination.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>move sample c:\test\disposable
1 directory moved.
C:\users\user>

After the move, the C:\test folder will have the following structure:

C:\test
│
└─disposable
        sample01.txt
        sample02.txt
        sample03.txt
        sample04.txt

If there is already a folder named C:\test\disposable, the structure will be as follows:

C:.
│
└─disposable
    │
    └─sample
            sample01.txt
            sample02.txt
            sample03.txt
            sample04.txt

Exercise

Question 1

The following command was used to move a folder.

move from to

What happens if there is already a folder named to?

Choose one answer.

  1. A confirmation message for overwriting is displayed
  2. The name of the source folder is used as the name of the destination folder
  3. The from folder is moved into the to folder
  4. An error occurs
Try more practice questions 171 questions by topic. Answer in your browser and check instantly. Start practicing →
#command prompt #batch files #arguments #command line #command