2012-01-09 74 views
2

我有以下文件結構:如何在Ant中複製目錄而不刪除目標目錄中的現有文件?

  • FolderToBeCopied
    • 文件夾1
      • somefile1
      • somefile2

我複製FolderToBeCopied給已經包含文件的位置:

  • DestinationFolder
    • 文件夾1
      • anotherfile1
      • anotherfile2

我複製使用FOL降脂在我的Ant構建腳本:

<copy overwrite="true" todir="DestinationFolder"> 
      <fileset dir="FolderToBeCopied" includes="**"> 
      </fileset> 
     </copy> 

然而,當我運行構建腳本,它複製文件somefile1和somefile2到文件夾1在目的地,而是在文件夾1(即已經刪除的文件。 anotherfile1,anotherfile2)。有沒有辦法阻止它刪除目標文件夾中已有的文件?

回答

1

是:在構建腳本中找到delete元素,刪除DestinationFolder並刪除它。

copy doesn't deleteoverwrite只意味着「複製即使目標比源更早」。

+1

另一種可能性是destinationFolder不在那裏擺在首位。然後它可以讓人認爲它已被刪除。 – 2013-04-11 11:59:28

0

爲了防止在目標文件夾中現有文件刪除,你可以做一個備份後附加一個時間戳的文件名:

<project name="demoSO" basedir="."> 

    <tstamp> 
    <format property="touch.time" pattern="yyMMddHHmmssSSS"/> 
    </tstamp> 

    <target name="copyMyFiles"> 
    <copy todir="DestinationFolder" includeemptydirs="false"> 
     <fileset dir="FolderToBeCopied"> 
     </fileset> 
     <mapper type="glob" from="*" to="*-${touch.time}"/> 
    </copy> 
    </target> 

</project> 
相關問題