[英]Copying files from a dynamically created folder over a network using batch files?
I am using TFS2013 and when a build is completed, a new sub-folder would be created inside the Drop Folder. 我使用的是TFS2013,构建完成后,将在放置文件夹内创建一个新的子文件夹。 How can we copy files from this folder to another subfolder inside this folder (which has to be created by us) using batch files?
我们如何使用批处理文件将文件从此文件夹复制到该文件夹内的另一个子文件夹(必须由我们创建)? I have to run this batch file as Post-Build script in TFS2013 Build Arguments.
我必须在TFS2013 Build Arguments中将此批处理文件作为Post-Build脚本运行。
Problem is we need to take care of network paths, as the drop folder is located in Dev server. 问题在于我们需要照顾网络路径,因为放置文件夹位于Dev服务器中。 The batch file which I created runs perfectly fine when run from the Dev server itself but gives file not found error when run after a build.
从开发服务器本身运行时,我创建的批处理文件运行得很好,但是在构建后运行时,却显示找不到文件的错误。
Here is the code: 这是代码:
@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\"
:( Any help would be greatly appreciated! Thanks :) :(任何帮助将不胜感激!谢谢:)
mkdir "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\Tasks*"
rem this * is an invalid character ^
You need not test the created folder existence; 您无需测试创建的文件夹是否存在; just use
只是使用
md "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\NotificationGenerator" 2>NUL
md "\\HQVEBLD01\TestDrop\TSOLB\%latest%\_PublishedWebsites\Tasks" 2>NUL
Try pushd
if any used command does not support UNC paths : 如果任何使用的命令不支持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
When a UNC path is specified,
PUSHD
will create a temporary drive map and will then use that new drive.指定UNC路径后,
PUSHD
将创建一个临时驱动器映射,然后将使用该新驱动器。 The temporary drive letters are allocated in reverse alphabetical order, so ifZ:
is free it will be used first.临时驱动器字母以相反的字母顺序分配,因此,如果
Z:
空闲,则将首先使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.