2014-01-24 52 views
1

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

源F:/ direcoty一个(这是脚本将坐)

目标H:/ folder1中/文件夹2/naming_convention_SN1_date

捕获为 “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>

感谢您的帮助! 玫瑰

+0

你的问题不是很清楚。如果你需要一个递增的内部版本号,有一个buildnumber任务:http://ant.apache.org/manual/Tasks/buildnumber.html –

+0

谢谢!下面是命名约定的文件夹 – user3232823

+0

谢谢!以下是文件夹application_buildtype_Buldnumber_date的命名约定。现在脚本需要每次创建该文件夹,并且内部编号需要增加。可以说google_test_abd9_01282014已经存在,脚本需要创建下一个文件夹,哪个需要google_test_abd10_currentdate。并将文件和文件夹从源路径复制到此新创建的文件夹。 – user3232823

回答

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` 

谢谢!!