Copy files via the command prompt

Author: Tamara Smith
Date Of Creation: 27 January 2021
Update Date: 1 July 2024
Anonim
How To Copy The Files and Folders using COMMAND PROMPT DOS By Easy Method|Cmc It Program
Video: How To Copy The Files and Folders using COMMAND PROMPT DOS By Easy Method|Cmc It Program

Content

The command prompt in Windows can be very powerful when you learn to use some of the commands. You can get a lot more control with Command Prompt than with copying and pasting in Windows Explorer. Knowing how to get the most out of copy jobs is essential when managing a Windows server remotely. It is also useful if you want to be more efficient with your own system.

To step

Before you start

  1. Know which command to use. There are several ways to copy files using the command prompt. All commands can copy files from one place to another, but there are several cases where one command is more suitable for a particular task than another.
    • COPY - This is the standard file copy function. You can quickly copy files from one place to another. You can also use this command to merge files.
    • XCOPY - With the xcopy command copy your files and directory trees. This makes it more suitable for copying folders. xcopy also has many attributes that give advanced users more control over copying. The use of xcopy is now discouraged in favor of robocopy, but it still works.
    • ROBOCOPY - This is the latest command available from the Windows command prompt. It requires Windows Vista or later. Windows XP users can install the Windows 2003 Server Resource Kit Tools pack to use this feature. robocopy is designed to clone files and directories while keeping permissions and other attributes the same. It also ensures that you can keep better logs and that larger amounts of data are copied more reliably.

Method 1 of 3: COPY

  1. Copy a single file. The assignment copy is best used when you are going to copy a single file. To the standard copy command, you type copy sourcedestination. For example, to save the Example.txt from C: Users desktop to copy to D: backup, fill in the following:

    copy C: Users desktop Example.txt D: backup Example.txt

    • You must also provide the name of the new file. You can use this to rename the copied file if you wish.
    • To copy a file from your working directory, just type the filename of the source file. For example, if you run the above command while you are already in the directory C: Users desktop then the command looks like copy Example.txt D: backup Example.txt
  2. Copy all files in a folder. Use the *.* wildcard to copy all files from a folder at once. For example, to copy all files from the folder C: Users desktop to D: backup, enter the following:

    copy C: Users desktop *. * D: backup

    • The assignment copy will not copy hidden files. Use the command for that xcopy or robocopy.
    • You can copy all files from your current work location by typing *.* as the source. In the above example, if you are already in the folder C: Users desktop you type copy *. * D: backup.
  3. Copy files when the file or folder has a space in its name. If your source or destination location or file has a space in its name, you should enclose it with quotation marks. For example to save all files from C: Users My Documents to D: 2015 Backup to copy, type:

    copy "C: Users My Documents *. *" "D: 2015 Backup"

  4. Combine (concatenate) text files. One of the "hidden" features of copy is the ability to merge multiple files. This is very useful with plain text files. The contents of the first and second text files in the following command will be merged, in order, into the new file:

    copy file1.txt + file2.txt newFile.txt

    • This command assumes that file1.txt and file2.txt are in the current directory. You will need to add the path to the beginning of each file name if the files are each in a different location.

Method 2 of 3: XCOPY

  1. Use COPY for individual files. You're better off with copy for individual files. The assignment xcopy does not allow you to specify a directory or a file name as the target location.
  2. Use ROBOCOPY if you create scripts for creating backups.xcopy will be replaced in the future and its use discouraged. robocopy can do anything xcopy can. In addition, it is more versatile and reliable. Creating scripts with robocopy prepares them for the future.
  3. Copy a folder to another location. The main function of xcopy is copying folders or the contents of a folder from one location to another. For example, to view all contents of the director C: tools to copy to the new folder D: backup tools, type the following:

    xcopy C: tools * D: backup tools / e / i

    • /e tells xcopy to also copy all subdirectories in the source location. Also the empty directories.
    • / i tells xcopy to assume that the destination is a folder. This will force the new folder to be created during the copy.
    • This is especially useful when copying files from a CD or a DVD. The Read-Only attribute is automatically removed during copying.
  4. Use xcopy to copy hidden files. One of the biggest benefits of xcopy above copy is the ability to copy hidden and system files. Add the / h modifier to also copy hidden files.

    xcopy C: tools * D: backup tools / e / i / h

Method 3 of 3: ROBOCOPY

  1. Use robocopy to easily copy folders. The assignment robocopy replaces xcopy. You can quickly copy entire folders without worrying about indicating the content. For example, to view all content of C: tools to D: backup tools To copy, enter the following:

    robocopy C: tools D: backup tools / e

    • The /e modifier tells robocopy to include all subdirectories as well. So also the empty folders.
    • robocopy will automatically hide and copy system files. You create new directories with it, if they do not yet exist in the target location.
  2. Mirror a directory. Mirroring a directory is great for backing up. The mirror option of robocopy will copy all content from the source to the destination. Then it will erase everything at the destination location that is not present in the source. This ensures that your backup only consists of the latest versions of your files. For example C: Users My Documents to flip to D: backup My Documents, type the following:

    robocopy "C: Users My Documents" "D: backup My Documents" / mir

    • This function keeps all rights of the original files intact.
  3. Activate restart. You can also indicate that the entire process will be redone if the connection is lost during the copy.

    robocopy "C: Users My Documents" "D: backup My Documents" / z

  4. Make a log of the copying process.robocopy also offers the possibility to create a log file. This can help identify problems or create an archive of what was copied.

    robocopy "C: Users My Documents" "D: backup My Documents" /log+:filename>.txt

    • The modifier / log + will append the new log file to the existing log file instead of overwriting it. If you prefer to simply overwrite the old log file, use /log:filename>.txt.