You are on page 1of 3

3/21/2016

(SS64)

XcopyCopyfilesandfolders|WindowsCMD|SS64.com

CMD

Syntax

Search

XCOPY
Copyfilesand/ordirectorytreestoanotherfolder.XCOPYissimilartotheCOPYcommandexceptthatithasadditional
switchestospecifyboththesourceanddestinationindetail.
XcopyhasbeendeprecatedunderVistaandWindows2008,thismeansthatwhilestillavailablenowitmightdisappearina
futureOSrelease.Toensureyourscriptsare'futureproof'useothertools(suchasRobocopy)insteadofxcopy.
XCOPYisparticularlyusefulwhencopyingfilesfromCDROMtoaharddrive,asitwillautomaticallyremovethereadonly
attribute.
Syntax
XCOPYsource[destination][options]
Key
source:Pathnameforthefile(s)tobecopied(acceptswildcards).
destination:Pathnameforthenewfile(s).

[options]canbeanycombinationofthefollowing:

SourceOptions

/ACopyfileswiththearchiveattributeset(default=Y)
/MCopyfileswiththearchiveattributesetand
turnoffthearchiveattribute,usethisoption
whenmakingregularBackups(default=Y)

/HCopyhiddenandsystemfilesandfolders(default=N)
/D:mmddyyyy
Copyfileschangedonorafterthespecifieddate.
Ifnodateisgiven,copyonlyfileswhose
sourcedate/timeisnewerthanthedestinationtime.
/UCopyonlyfilesthatalreadyexistindestination.

/SCopyfoldersandsubfolders
/ECopyfoldersandsubfolders,includingEmptyfolders.
canbeusedtomodify/T.
/EXCLUDE:file1[+file2][+file3]...
Thefilescaneachcontainoneormorefullorpartialpathnamestobeexcluded.
WhenanyofthesematchanypartoftheabsolutepathofaSOURCEfile,then
thatfilewillbeexcluded.
Forexample,specifyingastringlike\obj\or.objwillexclude
allfilesunderneaththedirectoryobjorallfileswiththe
.objextensionrespectively.

CopyOptions

/WPromptyoutopressakeybeforestartingtocopy.
/PPromptbeforecreatingeachfile.
/YSuppressprompttoconfirmoverwritingafile.
canbepresetintheCOPYCMDenvvariable.
/YPrompttoconfirmoverwritingafile.

/VVerifythatthenewfileswerewrittencorrectly.
/CContinuecopyingevenifanerroroccurs.

/IIfindoubtalwaysassumethedestinationisafolder
e.g.whenthedestinationdoesnotexist.
/BCopytheSymboliclinkitself,notthetargetofthefile.
/GAllowthecopyingofencryptedfilestoadestinationthatdoesnotsupportencryption.
http://ss64.com/nt/xcopy.html

1/3

3/21/2016

XcopyCopyfilesandfolders|WindowsCMD|SS64.com

/JCopyusingunbufferedI/O.Recommendedforverylargefiles.

/QDonotdisplayfilenameswhilecopying.
/FDisplayfullsourceanddestinationfilenameswhilecopying.
/LListonlyDisplayfilesthatwouldbecopied.
/ZCopyfilesinrestartablemode.Ifthecopyisinterruptedpartwaythrough,
itwillrestartifpossible.(useonslownetworks)
DestinationOptions
/ROverwritereadonlyfiles.
/TCreatefolderstructure,butdonotcopyfiles.
Donotincludeemptyfoldersorsubfolders.
/T/Ewillincludeemptyfoldersandsubfolders.
/KCopyattributes.XCOPYwillotherwiseresetreadonlyattributes.
/NIfatallpossible,useonlyashortfilename(8.3)whencreating
adestinationfile.Thiscanbenecessarywhencopyingbetweendisks
thatareformatteddifferentlye.gNTFSandVFAT,orwhenarchiving
datatoanISO9660CDROM.
/OCopyfileOwnershipandACLinformation.
/XCopyfileauditsettings(implies/O).
XCOPYwillacceptUNCpathnames.
ToalwaysoverwritedestinationfilesusetheCOPYCMDenvironmentvariable:SETCOPYCMD=/Y
WhencomparingDates/Timesthegranularity(thefinestincrementofthetimestamp)is2secondsforaFATvolumeand0.1
microsecondforanNTFSvolume.

Copyasinglele
InmostcasescopyingasinglefileisbestdonewiththeCOPYcommand.WhencopyingasinglefilewithXCOPY,
thereisnooptiontoindicateifthedestinationisafilenameoradirectory(withthefilenamedefaultingtothatofthe
sourcefile).
InsuchcasesXCOPYwillpromptwitha(localespecific)messagelike:
C:\>xcopyfoo.txtbar.txt
Doesfoo.txtspecifyafilename
ordirectorynameonthetarget
(F=file,D=directory)?
Addingawildcard(*)totheendofthedestinationwillsuppressthispromptanddefaulttocopyingasafile:
C:\>xcopyfoo.txtbar.txt*
C:foo.txt
1File(s)copied
Thisrequiresthesourceandtargetfileextensionstobethesamelength,typically3characters.

InsucientMemoryerror
AttemptingtoXCOPYasourcefilethathasapathnamelongerthantheWindowsmaximumpathlength(254
characters)willresultinaratherunhelpful'InsufficientMemory'error,theoperationwillthenhalt.Thisbugwhichhas
beenaroundforover10yearsmakesXCOPYapoorchoiceforanykindofbackupscript,useROBOCOPYinstead.
Examples:
Copyafile:
echoF|XCOPYC:\utils\MyFile.txtD:\Backup\CopyFile.txt
Copyafolder:
XCOPYC:\utilsD:\Backup\utils/i
Copyafolderincludingallsubfolders.
XCOPYC:\utils\*D:\Backup\utils/s/i
Itiseasiertocopythantothink,hencefashion~WallaceStevens
http://ss64.com/nt/xcopy.html

2/3

3/21/2016

XcopyCopyfilesandfolders|WindowsCMD|SS64.com

Related:
COPYCopyoneormorefilestoanotherlocation
DELDeletefiles
MOVEMoveafilefromonefoldertoanother
ROBOCOPYRobustFileandFolderCopy
PowerShell:CopyItemCopyanitemfromonelocationtoanother
Equivalentbashcommand(Linux):cpCopyoneormorefilestoanotherlocation

CopyrightSS64.com19992016
Somerightsreserved

http://ss64.com/nt/xcopy.html

3/3