使用相对文件名进行路径转换

发布于 2024-12-18 04:18:00 字数 578 浏览 6 评论 0原文

在文件夹 src 中,我有一组包含 java 源代码的子文件夹:

/a/A.java

/a/b/B.java

/a/b/c/C.java

我需要一个具有以下值的属性:

src/a/A.java,src/a/b/B.java,src/a/b/c/C.java

I尝试了以下操作:

<pathconvert property="list-of-files">
  <globmapper from="*" to="src/*"/>
  <fileset dir=${src-folder}/>
</pathconvert>

但我最终在我的财产上得到以下值:

src/full/path/to/folder_a/a/A.java,src/full/path/to/folder_a/a/b/B.java,src/full/path/to/folder_a/a/b/c/C.java

我怎样才能实现我想要的?任何意见表示赞赏!

In folder, src, I have a set of subfolders with java source code:

/a/A.java

/a/b/B.java

/a/b/c/C.java

I need a property with the following value:

src/a/A.java,src/a/b/B.java,src/a/b/c/C.java

I tried the following:

<pathconvert property="list-of-files">
  <globmapper from="*" to="src/*"/>
  <fileset dir=${src-folder}/>
</pathconvert>

but I end up with the following value on my property:

src/full/path/to/folder_a/a/A.java,src/full/path/to/folder_a/a/b/B.java,src/full/path/to/folder_a/a/b/c/C.java

How can I accomplish what I want? Any input is appreciated!

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

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

发布评论

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

评论(3

三寸金莲 2024-12-25 04:18:00

您可以使用 pathconvertmap 参数来实现此目的。

首先通过将其路径附加到 basedir 属性的值来获取 src 目录的完整路径。然后将其用作地图的 from 属性。

<property name="src.dir" value="${basedir}${file.separator}${src-folder}"/>
<pathconvert property="list-of-files">
  <map from="${src.dir}" to="src"/>
  <fileset dir="${src-folder}"/>
</pathconvert>

You can use the map parameter of pathconvert for this.

First get the full path to your src dir by appending its path to the value of the basedir property. Then use that as the from attribute of your map.

<property name="src.dir" value="${basedir}${file.separator}${src-folder}"/>
<pathconvert property="list-of-files">
  <map from="${src.dir}" to="src"/>
  <fileset dir="${src-folder}"/>
</pathconvert>
嗫嚅 2024-12-25 04:18:00

以防万一,如果有人需要获取资源的相对文件路径并将它们相应地映射到 URL 路径,因此它在 Windows 和 *nix 上都适用,解决方案是:

<pathconvert dirsep="/" pathsep=";" property="css.files.list">
    <map from="${basedir}/" to="" /><!-- This is the trick. Remove slash to make path absolute. -->
    <fileset dir="." includes="${src.dir}/**/*.css" />
</pathconvert>

Just in case if someone needs to get relative file paths of resources and map them to URL paths accordingly, so it works both on Windows and *nix the solution is:

<pathconvert dirsep="/" pathsep=";" property="css.files.list">
    <map from="${basedir}/" to="" /><!-- This is the trick. Remove slash to make path absolute. -->
    <fileset dir="." includes="${src.dir}/**/*.css" />
</pathconvert>
初见终念 2024-12-25 04:18:00

尝试以下之一:(

<pathconvert property="list-of-files">
  <globmapper from="*" to="src/*"/>
  <cutdirsmapper dirs="N"/>
  <fileset dir=${src-folder}/>
</pathconvert>

此处 N - 要删除的目录数(必须为正数))

或以下:
处理文件列表之后

<mapper type="flatten"/>
<flattenmapper/>

在您的代码片段通过希望此帮助=)

Try either this one:

<pathconvert property="list-of-files">
  <globmapper from="*" to="src/*"/>
  <cutdirsmapper dirs="N"/>
  <fileset dir=${src-folder}/>
</pathconvert>

(here N - Number of directories to strip (must be a positive number))

or this:
after piece of your code treat list-of-files through the

<mapper type="flatten"/>
<flattenmapper/>

Hope this help =)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文