批處理檔案中使用xcopy命令複製檔案到指定位置
阿新 • • 發佈:2022-04-18
網路搜尋能夠找到很多相關的文章,
但還是有幾個注意事項需要記錄一下:
1.相對路徑;
2.長檔名;
3.路徑中有空格;
4.排除特定檔案;
5.管理員許可權執行bat檔案。
解決方法如下:
1.
使用%~dp0訪問bat檔案所在的位置,
其具體含義可以進行網路搜尋,
說實在的,
我也沒搞明白呢。
2.
3.
兩個問題使用同一方法解決,
貌似時要定義一個變數,
類似如下:
set target=%C:\ProgramData\Autodesk\C3D 2022\chs\MySubassemblyHelp%。
4.
需要設定一個特定問文字檔案,
在這個檔案中設定需要排除的檔案。
檔名:exclude.txt,
檔案內容:
.bat
.txt
5.
搜尋到一串指令碼命令,
也不知道具體含義。
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
完整的bat檔案內容如下:
@echo off %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exitset target=%C:\ProgramData\Autodesk\C3D 2022\chs\MySubassemblyHelp% xcopy "%~dp0\*.*" "c:%target%" /d /y /e /exclude:%~dp0\exclude.txt
bat檔案與做需要複製的檔案(htm檔案)在同一位置,
使用上面的bat檔案,
實現了將其htm檔案複製到指定位置的需求。