我正在使用TFS2013,当构建完成时,将在Drop文件夹中创建一个新的子文件夹。我们如何使用批处理文件将文件从此文件夹复制到此文件夹内的另一个子文件夹(必须由我们创建)? 我必须在TFS2013 Build Arguments中将此批处理文件作为Post-Build脚本运行。
问题是我们需要处理网络路径,因为drop文件夹位于Dev服务器中。 我创建的批处理文件在从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\"
:( 任何帮助将不胜感激!谢谢:)
答案 0 :(得分:0)
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 paths,请尝试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:
是免费的,它将是 首先使用。