CMD move command moving files (clips) _dos/bat

Source: Internet
Author: User
Many times, when I see someone replying to "How to move a file from A to B", the advice is often to copy the files with the Copy command, and then delete the files and folders using Del and Rd. The reply had no idea that the procedure he had given was too tedious to realize that the system had provided a command to move files directly move!

The use of move is very simple and the basic format is move a B. Here, a indicates the file or folder where you want to perform the move operation, b indicates where a is saved after a is moved, and a can use a relative path, an absolute path, or even a wildcard character, but when move performs the function of moving a file, B can only be a directory path, not a file path-- It's hard to imagine how the operating system would feel if you were to move the A.txt file to the B.txt file. For example: Move A.txt d:\test, which means that the a.txt in the current directory is moved to the D:\test directory; move C:\test.txt d:\, which means that the test.txt files under the C-packing directory are moved to the D-packing directory; moving C:\*.txt D : \ means to move the text file in the C-packing directory to the D-packing directory.

In addition, you need to pay special attention to the following: move is not moving a folder across partitions. Thanks for Zqz0012005 's reminder.

As mentioned above, if you want to move a.txt to the B.txt file, the operating system will be very unhappy.

What if you do?

Move A.txt b.txt!

You will find that for your Hu Yu, the operating system does not stop you, it is obedient to carry out your command, but the result is not as you expect, the a.txt into the b.txt inside, but the a.txt renamed B.txt.

In a command such as Move A B, moves have the basic function of moving files (folders), as well as the effect of renaming files (clips), and, depending on the circumstances, decide:

1, if a, B is the same folder name, then move a to B directory;
2, if A is a filename,
When ①b is a folder name, a will be moved to the B directory;
When ②b is a filename, a will be renamed to B, and if B is in another directory, it means to rename B at the same time as move a to the directory where B is located.

Once you understand the use of move, when renaming a file, it's easy to make a trade-off between Ren and move: If you simply rename the file, Ren and move are optional, but move is a little weird; Also rename the file, select Move C:\test.txt D:\abc\1.txt's writing will be one-step, and the first move C:\test.txt d:\abc, then Ren d:\abc\test.txt 1.txt will appear cumbersome, the most undesirable Practice, is the first copy, and then Del/rd, and finally Ren, this is the pursuit of code to the essence of Jane's people can not tolerate wasteful behavior.

Sometimes, the move process does not smooth sailing, the more common situation is: The destination has duplicate file exists, the system can not find the specified file.

First to say the case of duplicate files.

If a duplicate file appears, move will not succeed, it will be very thoughtful to ask you: Rewrite xx? (Yes/no/all): of which, XX represents the destination of the duplicate file. If you select Yes, the duplicate name file is overwritten, and if you select No, the move action is discarded; If you select all, then in bulk move, if there is a file with the same names, you will no longer ask for coverage, but directly overwrite the duplicate file.

If you hate to jump out of this message is very troublesome, and your real goal is to forcibly overwrite all the duplicate files, add a/y switch to move, written move/y a B on it-in the cmd window, by default, move is with the/-y switch, That is, the default will appear duplicate file information, but this default switch can be omitted, and in the batch script, move default with the/y switch, does not appear the same name prompts directly overwrite the same file, and CMD window in the case just the opposite.


Again, the system could not find the specified file.

Sometimes, you will be very strange, move a B, when a clearly exists, why do not have the right to remind you: "The system can not find the specified file"? Isn't that a lie?

However, Microsoft is also very innocent: there are too many mistakes, so I have to give specific reasons for each error situation, I do not have such a great avatar ah? We do technology is also not easy Ah, can remind you can't find the designated documents, we have tried, you are always a lot of excuse me.

Come on, let's find out why we're doing it ourselves.

Originally, move does not have the avatar of Dir, it is not able to identify files with hidden or system attributes in front of these files, it becomes blind, but this does not say move is too incompetent, but Microsoft for security reasons, limit a lot of dangerous commands to the hidden or system properties of the file direct operation--del, Ren is this pair of virtues, and Rd command, is a slip through the slip, is an exception, otherwise, Microsoft's system will not have to play a patch to say.

How to solve this problem?

No way, you can only honestly use the attrib command to remove these files hidden or system attributes, and then move bar. As for writing batch processing, how to determine which files need to be attrib before move, which files can move directly, it is not part of the scope of this article to discuss, but also ask readers to focus on other topics related to the discussion 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.