以開源記牌器https://github.com/Epix37/Hearthstone-Deck-Tracker 為例,Hearthstone Deck Tracker項目中的后期生成事件命令行:
if "$(ConfigurationName)" == "Release" (
rmdir /S /Q "..\Hearthstone Deck Tracker"
mkdir "..\Hearthstone Deck Tracker"
mkdir "..\Hearthstone Deck Tracker/Images"
mkdir "..\Hearthstone Deck Tracker/Files"
mkdir "..\Hearthstone Deck Tracker/Plugins"
xcopy /E /Y "Images\*.*" "..\Hearthstone Deck Tracker\Images"
xcopy /E /Y "Files\*.*" "..\Hearthstone Deck Tracker\Files"
xcopy /Y "HearthstoneDeckTracker.exe" "..\Hearthstone Deck Tracker"
xcopy /Y "HearthstoneDeckTracker.exe.config" "..\Hearthstone Deck Tracker"
ren "..\Hearthstone Deck Tracker\HearthstoneDeckTracker.exe" "Hearthstone Deck Tracker.exe" //重命名,目的是去掉空格
ren "..\Hearthstone Deck Tracker\HearthstoneDeckTracker.exe.config" "Hearthstone Deck Tracker.exe.config" //重命名,目的是去掉空格
xcopy /Y "HDTHelper.exe" "..\Hearthstone Deck Tracker"
xcopy /Y "HDTUpdate.exe" "..\Hearthstone Deck Tracker"
xcopy /Y "HDTUninstaller.exe" "..\Hearthstone Deck Tracker"
xcopy /Y "HtmlAgilityPack.dll" "..\Hearthstone Deck Tracker"
xcopy /Y "MahApps.Metro.dll" "..\Hearthstone Deck Tracker"
xcopy /Y "Newtonsoft.Json.dll" "..\Hearthstone Deck Tracker"
xcopy /Y "System.Windows.Interactivity.dll" "..\Hearthstone Deck Tracker"
xcopy /Y "Version.xml" "..\Hearthstone Deck Tracker" )
rmdir 參數說明
xcopy 參數說明
xcopy /?
Copies files and directory trees.
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B] [/J]
[/EXCLUDE:file1[+file2][+file3]...]source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
doesn't change the attribute.
/M Copies only files with the archive attribute set,
turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/V Verifies the size of each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.
/B Copies the Symbolic Link itself versus the target of the link.
/J Copies using unbuffered I/O. Recommended for very large files.The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy
ren是rename的縮寫,如果需要給文件重命名,可使用rename命令。
rmdir /S /Q "..\IntelligentBuilding"
mkdir "..\IntelligentBuilding"
xcopy /Y "AxInterop.SliderExLib.dll" "..\IntelligentBuilding"
xcopy /Y "ClientApp.exe" "..\IntelligentBuilding"
xcopy /Y "ClientApp.exe.config" "..\IntelligentBuilding"
xcopy /Y "DevExpress.BonusSkins.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Charts.v16.1.Core.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Data.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Office.v16.1.Core.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Pdf.v16.1.Core.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Pdf.v16.1.Drawing.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Printing.v16.1.Core.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.RichEdit.v16.1.Core.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Sparkline.v16.1.Core.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Utils.v16.1.UI.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.Utils.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraBars.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraCharts.v16.1.UI.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraCharts.v16.1.Wizard.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraCharts.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraEditors.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraGauges.v16.1.Core.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraGauges.v16.1.Win.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraGrid.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraLayout.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraNavBar.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraPrinting.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraRichEdit.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraTreeList.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "DevExpress.XtraVerticalGrid.v16.1.dll" "..\IntelligentBuilding"
xcopy /Y "Interop.SliderExLib.dll" "..\IntelligentBuilding"
xcopy /Y "log4net.dll" "..\IntelligentBuilding"
實戰
現在有一個hotfix文件夾,5.1.0.0 Hotfix。在這個文件夾下有2個子文件夾
hotfix_5.1.1_Generic_20180911 這個子文件夾下有一些module文件夾
hotfix_5.1.2_Generic_20180912 這個子文件夾是新創建的,現在需要把上面的子文件夾的folder復制到這個子文件夾
在hotfix_5.1.1_Generic_20180911文件夾中執行命令
xcopy /t . ..\hotfix_5.1.2_Generic_20180912\
xcopy /t . '..\..\5.1.0.0 Hotfix\hotfix_5.1.2_Generic_20180912\' 這個命令執行失敗,提示說,創建目錄失敗。
谷歌查詢之后,發現可以通過powershell的copy-item命令來操作
https://stackoverflow.com/questions/44678962/how-to-copy-folder-structure-only-with-powershell
