簡體   English   中英

使用批處理文件通過網絡從動態創建的文件夾復制文件?

[英]Copying files from a dynamically created folder over a network using batch files?

我使用的是TFS2013,構建完成后,將在放置文件夾內創建一個新的子文件夾。 我們如何使用批處理文件將文件從此文件夾復制到該文件夾​​內的另一個子文件夾(必須由我們創建)? 我必須在TFS2013 Build Arguments中將此批處理文件作為Post-Build腳本運行。

問題在於我們需要照顧網絡路徑,因為放置文件夾位於Dev服務器中。 從開發服務器本身運行時,我創建的批處理文件運行得很好,但是在構建后運行時,卻顯示找不到文件的錯誤。

這是代碼:

@echo off
::Date - 6/16/2015  ;; 6:58PM
::Find the directory containing the latest build - latest created directory.
FOR /f "delims=" %%x in ('dir "\\HQVEBLD01\TestDrop\TSOLB\" /od /b') do set latest=%%x
if not exist "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites" mkdir "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites"
:: above line creates published websites folder if it doesn't already exist
if not exist "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\NotificationGenerator" mkdir "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\NotificationGenerator"
if not exist "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\Tasks" mkdir "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\Tasks"


::first copy common files. our first folder is scheduled tasks folder
::
xcopy.exe "\\HQVEBLD01\TestDrop\TSOLB\%latest%\A.dll" "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\Tasks\"

:(任何幫助將不勝感激!謝謝:)

mkdir "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\Tasks*"
rem                             this * is an invalid character     ^

您無需測試創建的文件夾是否存在; 只是使用

md "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\NotificationGenerator"  2>NUL
md "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\Tasks" 2>NUL

如果任何使用的命令不支持UNC路徑,請嘗試pushd

@echo off

pushd "\\HQVEBLD01\TestDrop\TSOLB\"

::Date - 6/16/2015  ;; 6:58PM
::Find the directory containing the latest build - latest created directory.

FOR /f "delims=" %%x in ('dir /ad /od /b') do set "latest=%%x"
::                            ^
mkdir "%latest%\_PublishedWebsites" 2>nul
:: above line creates published websites folder if it doesn't already exist
mkdir "%latest%\_PublishedWebsites\NotificationGenerator" 2>nul
mkdir "%latest%\_PublishedWebsites\Tasks" 2>nul


::first copy common files. our first folder is scheduled tasks folder
::
xcopy.exe "%latest%\A.dll" "%latest%\_PublishedWebsites\Tasks\"

popd

指定UNC路徑后, PUSHD將創建一個臨時驅動器映射,然后將使用該新驅動器。 臨時驅動器字母以相反的字母順序分配,因此,如果Z:空閑,則將首先使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM