How do I copy using the command line in windows?

Xcopy <Source> [<Destination>] [/w] [/p] [/c] [/v] [/q] [/f] [/l] [/g] [/d [:MM-DD-YYYY]] [/u] [/i] [/s [/e]] [/t] [/k] [/r] [/h] [{/a | /m}] [/n] [/o] [/x] [/exclude:FileName1[+[FileName2]][+[FileName3]] [{/y | /-y}] [/z] [/b] [/j]
 


Description

<Source>

Required. Specifies the location and names of the files you want to copy. This parameter must include either a drive or a path.

[<Destination>]

Specifies the destination of the files you want to copy. This parameter can include a drive letter and colon, a directory name, a file name, or a combination of these.

/w

Displays the following message and waits for your response before starting to copy files: 

Press any key to begin copying file(s)

/p

Prompts you to confirm whether you want to create each destination file.

/c

Ignores errors.

/v

Verifies each file as it is written to the destination file to make sure that the destination files are identical to the source files.

/q

Suppresses the display of xcopy messages.

/f

Displays source and destination file names while copying.

/l

Displays a list of files that are to be copied.

/g

Creates decrypted Destination files when the destination does not support encryption.

/d [:MM-DD-YYYY]

Copies source files changed on or after the specified date only. If you do not include a MM-DD-YYYY value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.

/u

Copies files from Source that exist on Destinationonly.

/i

If Source is a directory or contains wildcards and Destination does not exist, xcopy assumes Destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether Destination is a file or a directory.

/s

Copies directories and subdirectories, unless they are empty. If you omit /sxcopy works within a single directory.

/e

Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options. /t

/t

Copies the subdirectory structure (that is, the tree) only, not files. To copy empty directories, you must include the /e command-line option.

/k

Copies files and retains the read-only attribute on Destination files if present on the Source files. By default, xcopy removes the read-only attribute.

/r

Copies read-only files.

/h

Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files

/a

Copies only Source files that have their archive file attributes set. /a does not modify the archive file attribute of the source file. For information about how to set the archive file attribute by using attrib, see Additional references.

/m

Copies Source files that have their archive file attributes set. Unlike /a/m turns off archive file attributes in the files that are specified in the source. For information about how to set the archive file attribute by using attrib, see Additional references.

/n

Creates copies by using the NTFS short file or directory names. /n is required when you copy files or directories from an NTFS volume to a FAT volume or when the FAT file system naming convention (that is, 8.3 characters) is required on the Destination file system. The Destination file system can be FAT or NTFS.

/o

Copies file ownership and discretionary access control list (DACL) information.

/x

Copies file audit settings and system access control list (SACL) information (implies /o).

/exclude:FileName1[+[FileName2][+[FileName3](…)]

Specifies a list of files. At least one file must be specified. Each file will contain search strings with each string on a separate line in the file.

When any of the strings match any part of the absolute path of the file to be copied, that file will be excuded from being copied. For example, specifying the string, \obj\ or .obj will exclude all files underneath the directory obj or all files with the .objextension.

/y

Suppresses prompting to confirm that you want to overwrite an existing destination file.

/-y

Prompts to confirm that you want to overwrite an existing destination file.

/z

Copies over a network in restartable mode.

/b

Copies the symbolic link instead of the files. This parameter was introduced in Windows Vista®.

/j

Copies files without buffering. Recommended for very large files. This parameter was added introduced in Windows Server® 2008 R2.

/?

 

Examples:

To copy all the files and subdirectories (including any empty subdirectories) from drive A to drive B, type: 

 
 
xcopy a: b: /s /e 

To include any system or hidden files in the previous example, add the/h command-line option as follows:

 
 
xcopy a: b: /s /e /h

To update files in the \Reports directory with the files in the \Rawdata directory that have changed since December 29, 1993, type: 

 
 
xcopy \rawdata \reports /d:12-29-1993

To update all the files that exist in \Reports in the previous example, regardless of date, type:

 
 
xcopy \rawdata \reports /u

To obtain a list of the files to be copied by the previous command (that is, without actually copying the files), type:

 
 
xcopy \rawdata \reports /d:12-29-1993 /l > xcopy.out

The file xcopy.out lists every file that is to be copied.

To copy the \Customer directory and all subdirectories to the directory \\Public\Address on network drive H:, retain the read-only attribute, and be prompted when a new file is created on H:, type:

 
 
xcopy \customer h:\public\address /s /e /k /p

To issue the previous command, ensure that xcopycreates the \Address directory if it does not exist, and suppress the message that appears when you create a new directory, add the /i command-line option as follows:

 
 
xcopy \customer h:\public\address /s /e /k /p /i

You can create a batch program to perform xcopyoperations and use the batch if command to process the exit code if an error occurs. For example, the following batch program uses replaceable parameters for the xcopy source and destination parameters:


this batch program to copy all files in the C:\Prgmcode directory and its subdirectories to drive B, type: 

 
 
copyit c:\prgmcode b:

The command interpreter substitutes C:\Prgmcode for %1 and B: for %2, then uses xcopy with the /e and /scommand-line options. If xcopyencounters an error, the batch program reads the exit code and goes to the label indicated in the appropriate IF ERRORLEVEL statement, then displays the appropriate message and exits from the batch program.

  • 25 Users Found This Useful
Was this answer helpful?

Related Articles

How do I change my remember password options in Google Chrome

Manage your website passwords This article applies to the Google Chrome browser on Windows,...

Change time is Gmail

Correct Your Gmail Time Zone To set your Gmail time zone: Click the gear in your Gmail's...

How to speed up Windows XP use at your own risk

Warning: occasionally people break their PC badly by using this list of suggestions. Usually...

How to run cmd in escalated mode with admin rights to modify firewall

a solution: runas /user:administrator@domainname.local cmd then in the resulting command...

How do I enable auto login in Windows

This article describes how to configure Windows to automate the logon...