如何将一个文件复制到多个子目录

发布于 2024-10-31 15:41:12 字数 1535 浏览 1 评论 0原文

我尝试使用 nant 因为我认为它是最简单的,但我对任何适用于 Windows XP 的解决方案持开放态度。

我有以下文件夹结构

basefolder
    folder1
    folder2
        subfolder1
            code
                solutionname1
                     projectname.interface
                     projectname.simulation
                     projectname.testcase
                         bin
                             release
    folder3
    ...
    folderN

folder1-folderN都具有与folder2相同的目录结构。我想将一个文件复制到每个文件夹N中的release文件夹中。

我目前有以下 nant 脚本,

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://nant.sf.net/release/0.90/nant.xsd" name="CopyDll" default="FileCopy">
  <property name="fileToCopy"
            value="C:\file.dll"
            overwrite="false"/>
  <property name="baseDirectory" value="${directory::get-current-directory()}" overwrite="false"/>
  <target name="FileCopy"
          description="Copies file to multiple directories">
    <foreach item="Folder"
             in="${baseDirectory}"
             property="foldername">
      <in>
        <items>
          <include name="**\**\**\*.TestCase\bin\Release"/>
        </items>
      </in>
      <do>
        <copy file="${fileToCopy}"
              todir="${foldername}"/>
        <echo message="Copied file to ${foldername}"/>
      </do>
    </foreach>   
  </target>
</project>

它将 file.dll 复制到每个folderN目录。 我做错了什么? 有更好的方法吗?

I'm trying to use nant because I thought it would be the easiest, but i'm open to any solution that works on windows xp.

I have the following folder structure

basefolder
    folder1
    folder2
        subfolder1
            code
                solutionname1
                     projectname.interface
                     projectname.simulation
                     projectname.testcase
                         bin
                             release
    folder3
    ...
    folderN

folder1 - folderN all have the same directory structure as folder2. I want to copy a file to the release folder in each folderN.

I currently have the following nant script

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://nant.sf.net/release/0.90/nant.xsd" name="CopyDll" default="FileCopy">
  <property name="fileToCopy"
            value="C:\file.dll"
            overwrite="false"/>
  <property name="baseDirectory" value="${directory::get-current-directory()}" overwrite="false"/>
  <target name="FileCopy"
          description="Copies file to multiple directories">
    <foreach item="Folder"
             in="${baseDirectory}"
             property="foldername">
      <in>
        <items>
          <include name="**\**\**\*.TestCase\bin\Release"/>
        </items>
      </in>
      <do>
        <copy file="${fileToCopy}"
              todir="${foldername}"/>
        <echo message="Copied file to ${foldername}"/>
      </do>
    </foreach>   
  </target>
</project>

This copies file.dll to each folderN directory.
What am I doing wrong?
Is there a better way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征﹌骨岁月お 2024-11-07 15:41:12

我想通了。我不得不改变我的 foreach 看起来像这样

    <foreach item="Folder"
             property="foldername">
      <in>
        <items>
          <include name="${baseDirectory}\**\*.TestCase\bin\Release"/>
        </items>
      </in>
      <do>
        <copy file="${fileToCopy}"
              todir="${foldername}"/>
        <echo message="Copied file to ${foldername}"/>
      </do>
    </foreach>   

I figured it out. I had to change my foreach to look like this

    <foreach item="Folder"
             property="foldername">
      <in>
        <items>
          <include name="${baseDirectory}\**\*.TestCase\bin\Release"/>
        </items>
      </in>
      <do>
        <copy file="${fileToCopy}"
              todir="${foldername}"/>
        <echo message="Copied file to ${foldername}"/>
      </do>
    </foreach>   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文