使用Ant替换文件名中的所有下划线?

use*_*977 2 ant

使用Ant任务执行此操作的最佳方法是什么:

从一堆文本文件开始,其名称如下:

Filename_With_Underscores.txt

Another_Filename_With_Underscores.txt

Yet_Another_Filename_With_Underscores.txt
Run Code Online (Sandbox Code Playgroud)

把它们变成这个:

Filename+With+Underscores.txt

Another+Filename+With+Underscores.txt

Yet+Another+Filename+With+Underscores.txt
Run Code Online (Sandbox Code Playgroud)

我实际上需要更改每个文本文件所包含的同名文件夹,也就是说,从这个文件夹/文件结构开始:

Filename_With_Underscores/Filename_With_Underscores.txt
Run Code Online (Sandbox Code Playgroud)

把它变成这个:

Filename+With+Underscores/Filename+With+Underscores.txt
Run Code Online (Sandbox Code Playgroud)

但如果我知道如何重写文本文件名,我可以处理.

我会知道如何用文件内容中的加号替换所有下划线,使用replaceregexp,但我该如何对文件夹和文件名本身这样做呢?

我过去曾使用映射器重写文件夹和文件名,例如:

 <target name="dita_wrap" description="Wraps each file in a folder with the same name as the file, copies all to new location">
    <copy todir="output" verbose="true">
    <fileset dir="source"
    includes="*/*.dita" />
     <regexpmapper handledirsep="true" from="^(.*)/([^/]*)\.dita$"
     to="\1/\2/\2.dita" />
    </copy>
</target>
Run Code Online (Sandbox Code Playgroud)

然而得到类似的东西来捕获和替换文件名中的每个下划线,无论可能有多少下划线,都是在逃避我.有什么建议?

mar*_*ton 5

你需要一个<filtermapper>,例如:

<copy todir="output" verbose="true">
  <fileset dir="source" includes="*/*.txt" />
  <filtermapper>
    <replacestring from="_" to="+"/>
  </filtermapper>
</copy>
Run Code Online (Sandbox Code Playgroud)

适合我:

$> find . -type f
./build.xml
./source/Filename_With_Underscores/Filename_With_Underscores.txt
./output/Filename+With+Underscores/Filename+With+Underscores.txt
Run Code Online (Sandbox Code Playgroud)