2011-05-10 3 views
2

dir에 들어있는 모든 파일을 other에있는 모든 파일로 바꿔야합니다.NAnt : 다른 디렉토리에서 파일 세트를 바꾸는 방법

foreach (string file in /foo/var) 
    { 
    srcFile = "/other/dir/" + GetFileName(file); 
    Copy(srcFile, file); 
    } 

내가 /foo/var/other/dir 모두에 존재하는 경우에만 파일을 대체해야합니다

이 작업에 대한 의사 코드가 될 것입니다. 또한 /foo/var에 존재하고 /other/dir에 존재하지 않는 파일이 있고 그 반대의 경우도 있습니다.

NAnt를 사용하여 가장 좋은 방법은 무엇입니까?

답변

2

이 작업을 수행해야합니다. 루트 대상 디렉토리의 파일 만보고 하위 폴더는 무시합니다. 당신이 하위 폴더

<project name="Sync" default="sync" xmlns="http://nant.sf.net/release/0.85/nant.xsd"> 

    <property name="source.path" value="D:\test\source\" /> 
    <property name="target.path" value="D:\test\target\" /> 

    <target name="sync" description="Copies only the matching files to a folder"> 
    <foreach item="File" property="targetFile"> 
     <in> 
     <items basedir="${target.path}"> <!-- include all files from the target path --> 
      <include name="*" /> <!-- this will not include subfolders --> 
     </items> 
     </in> 
     <do> 
     <if test="${file::exists(source.path + path::get-file-name(targetFile))}"> 
      <copy 
       file="${source.path + path::get-file-name(targetFile)}" 
       tofile="${targetFile}" 
       overwrite="true" 
       /> 
     </if> 
     </do> 
    </foreach> 
    </target> 
</project> 

내가

을 NANT 0.86으로 테스트에 파일을 포함 할 경우 좀 더 많은 작업이 필요합니다
관련 문제