How do I write a batch script that copies one directory to another, replaces old files?

前端 未结 5 523
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 09:59

I\'d like a batch script in Windows with which I can copy one directory to another. If this directory already exists, and then for each file that already exists in both with the

5条回答
  •  情深已故
    2021-02-01 10:32

    In your batch file do this

    set source=C:\Users\Habib\test
    set destination=C:\Users\Habib\testdest\
    xcopy %source% %destination% /y
    

    If you want to copy the sub directories including empty directories then do:

    xcopy %source% %destination% /E /y
    

    If you only want to copy sub directories and not empty directories then use /s like:

    xcopy %source% %destination% /s /y
    

提交回复
热议问题