CMD move command to move the file (folder)

Source: Internet
Author: User

Most of the time, when someone replies "how to move a file from A to B", the suggestion is that the copy command should be used to copy the file first, delete files and folders with Del and RD. The reviewer did not think that the operation process he provided was too cumbersome and he did not realize that the system had provided the command to move the file directly!

The use of move is very simple. The basic format is move a B. What do the operating system think when the hosts file is used. For example, move a.txt D :\testto move a.txt under the current directory to the Directory D: \ test; move c: \ test.txt D :\to move the test.txt file under the C root directory to the root directory of the d disk; move c :\*. txt d: \ indicates to move the text files in the C root directory to the D root directory.

In addition, you must note that move cannot move folders across partitions. Thanks for the reminder from zqz0012005.

Once said, if you want to move a.txt to B .txt, the operating system will be unhappy.

What if you do?

Move a.txt B .txt!

Stopped.

It turns out that in a command such as move a B, move has the basic function of moving a file (folder) and the function of renaming a file (folder). What does it do, depending on the situation:

1. If a and B are the same folder names, move a to the directory B;
2. If a is the file name,
① When B is the folder name, A will be moved to directory B;
② When B is the file name, A will be renamed to B. If B is located in another directory, it means that while moving A to B's directory, rename B.

Once you understand the usage of moving, when renaming a file, you can easily choose between Ren and move: If you simply rename the file, you can choose either Ren or move, but the move statement is a little weird. If you want to rename the file after moving the file, choose move c: \ test.txt D: \ ABC \ 1.txt is written in one step, while c: \ test.txt D: \ ABC is first moved, followed by Ren D: \ ABC \ test.txt 1.txt, the most undesirable practice is to copy, del/RD, and then Ren. This is the pursuit.CodeExtravagance and waste that can't be tolerated by people with ultimate precision and simplicity.

Sometimes, the move process is not smooth sailing. A common situation is that duplicate files exist in the destination, and the system cannot find the specified file.

First, let's talk about the situation of duplicate files.

If a duplicate file appears, the move operation will not succeed, and it will be considerate to ask you: do you want to rewrite XXX? (Yes/No/All): Here, ×× indicates the duplicate name file of the destination. If yes is selected, the duplicate files will be overwritten. If no is selected, the move operation will be abandoned. If all is selected, if a file with the same name exists during batch move, the system will not ask whether to overwrite the file, instead, the duplicate file is overwritten.

If you think it is troublesome to jump out of this prompt, and your real purpose is to forcibly overwrite all duplicate files, add a/Y switch to move, write it as move/y a B. In the CMD window, by default, move is performed with the/-Y switch, that is, by default, the duplicate file prompt is displayed, however, this default switch can be omitted. In the batch processing script, the move switch is/y by default, and the file with the same name is directly overwritten without the duplicate name prompt, it is the opposite of the situation in the CMD window.

The system cannot find the specified file.

Sometimes, you may be surprised that when moving a B, a clearly exists. Why do you want to remind you with an annoyance: "The system cannot find the specified file? Isn't that true?

However, Microsoft is also quite innocent: there are too many errors. I want to clarify the specific causes of each error. How can I be so powerful? It is not easy for us to engage in technology. We have tried our best to remind you that you cannot find the specified file. Please forgive me if you are old.

Come on, let's find the reason.

It turns out that moving has no Dir, and it cannot identify files with hidden or system attributes. In front of these files, it becomes blind. However, it cannot be said that moving is too incompetent, for the sake of security, Microsoft restricts many dangerous commands to perform direct operations on files with hidden or system attributes-Del and Ren are the same character, while RD commands are the fish of the Internet, this is an exception. Otherwise, Microsoft's system won't be patched.

How can this problem be solved?

No way. You can only honestly use the attrib command to remove the hidden or system attributes of these files. Move the file again. When writing batch processing, how to determine which files need to be attrib before moving, and which files can be directly moved does not fall into the scope discussed in this article, readers are also invited to pay attention to other topics related to the Forum.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.