使用增量版本创建目录

时间:2014-01-24 16:51:01

标签: xml ant

我有一种情况,我需要在创建目录后将文件从一个位置复制到另一个位置。

来源F:/ direcoty one(这是脚本所在的位置)

目标H:/ folder1 / folder2 / naming_convention_SN1_date

catch是“SN”部分每次需要增加一个

我正在尝试下面的代码。但不确定如何使其增量

<b> 
<target name="create directory">
    <mkdir dir="H:/folder1/folder2/{${JOB_NAME}.${BUILD_NUMBER}.date}"/>
</target>
    <copy todir="H:/folder1/folder2/{${JOB_NAME}.${BUILD_NUMBER}.date}">
 <fileset dir="src_dir" include="**/*"/>
</copy>
  

/ B个

感谢您的帮助!! 罗斯

1 个答案:

答案 0 :(得分:0)

感谢您的帮助!!我想通了。如果有人需要它,请把它放在这篇文章中。

`@echo on
setlocal EnableDelayedExpansion
set max_number=0
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c%%a%%b)

for /d %%d in (destination_location\folder_name_ABC%max_number%_%mydate%%) do (
set current_directory=%%~nxd
    call:StrLength name_length !current_directory!
 echo name_length
 echo !current_directory!
 echo !name_length!

    call:Substring directory_number,!current_directory!,26,!name_length!
    if !directory_number! gtr !max_number! (
        set max_number=!directory_number!
    )
)
set /a max_number+=1

mkdir "destination_location\folder_name_ABC%max_number%_%mydate%%"

echo Directory create = folder_name_ABC%max_number%_%mydate%%

echo copy in process..........

xcopy "Source_location"    "Destination_location\%folder_name%_BLD%max_number%_%mydate%%"     /D /E /Y

echo copy completed:

GOTO :EOF

:Substring
::Substring(retVal,string,startIndex,length)
:: extracts the substring from string starting at startIndex for the specified length
 SET string=%2%
 SET startIndex=%3%
 SET length=%4%
 if "%4" == "0" goto :noLength
 CALL SET _substring=%%string:~%startIndex%,%length%%%
 goto :substringResult
 :noLength
 CALL SET _substring=%%string:~%startIndex%%%
 :substringResult
 set "%~1=%_substring%"
GOTO :EOF
:StrLength
::StrLength(retVal,string)
::returns the length of the string specified in %2 and stores it in %1
set #=%2%
set length=0
:stringLengthLoop
if defined # (set #=%#:~1%&set /A length += 1&goto stringLengthLoop)
::echo the string is %length% characters long!
set "%~1=%length%"
GOTO :EOF`

谢谢!