简体   繁体   English

使用批处理文件通过网络从动态创建的文件夹复制文件?

[英]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 if Z: is free it will be used first. 临时驱动器字母以相反的字母顺序分配,因此,如果Z:空闲,则将首先使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Shell脚本将文件从一个文件夹复制到另一个文件夹 - Copying files from one folder to another using a shell script Shell 脚本:将带有通配符 (*) 的文件从一个文件夹复制到另一个文件夹 - Shell Script: Copying files with wildcard (*) to from one folder to another folder 使用批处理文件列出文件夹中的文件 - Listing the files inside a folder using batch file 在路径中使用空间以使用批处理脚本复制文件 - using space in path for copying files using batch script 将文件从一个目录中的文件夹复制到公用文件夹 - Copying files from folders in one directory to a common folder 从多个文件夹复制文件,其中文件名是文件夹的一部分 - Copying files from Multiple Folders Where the File Name is a part of the folder 需要使用批处理脚本将每 5000 个文件移动到新文件夹 - Need to move every 5000 files to new folder using batch script 批处理文件使用 findstr 查找多个字符串并将文件复制到文件夹 - Batch file to find multiple string using findstr and copy files to a folder 如何使用python自动通过网络发送文件? - How to automate the sending of files over the network using python? 将带有通配符的文件列表复制到新文件夹中 - Copying a list of files with wildcards into a new folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM