如何计算当前文件夹中的目录数量?
我想计算它遍历的每个文件夹中的目录数量。如果文件夹数量等于1,则继续遍历,否则选择当前文件夹路径。
我只想要文件夹分支之前的路径。
我正在编辑它并包含我想要的伪代码。
IF There are no .class files in the current directory
AND Multiple Folders in the current directory
THEN Use this folder path
更多编辑:
我如何在 Ant 或 Bash 中编码?我也向 Bash 提出这个问题。我可以通过 Ant 执行这段代码。
编辑(5 月 12 日)
现在我正在使用
<first>
<fileset dir="${classes.dir}" includes="/*">
<include name="**/*.class" />
</fileset>
</first>
它,它可以让我得到它按字母顺序搜索的第一个 .class。然后我得到的路径
<property name="classloc" value="${classes.dir}" relative="true" basedir="." />
当项目的文件夹结构如下所示时,这可以正常工作:
但是当文件夹结构分支并且根文件夹中没有 .class 时,那么我的代码仅获取到的路径其中一个文件夹和所有其他文件夹都将被忽略。我需要 .class 文件及其文件夹之前的文件夹路径。
I want to count the number of directories in each folder it traverses. If a number of folders are equal to one, continue traversing, else select the current folder path.
I just want the path of the folder before it branches out.
I am editing this and including a pseudo-code of what I want.
IF There are no .class files in the current directory
AND Multiple Folders in the current directory
THEN Use this folder path
More Edit:
How would I code this in Ant or Bash? I am opening this question to Bash too. I can execute this code through Ant.
Edit (12 May)
Right now I am using
<first>
<fileset dir="${classes.dir}" includes="/*">
<include name="**/*.class" />
</fileset>
</first>
which gets me the first .class it searches in alphabetical order. Which I then get the path of by
<property name="classloc" value="${classes.dir}" relative="true" basedir="." />
This works fine when the folder structure of a project is like this:
But when folder structure is branched out and no .class is outside in the root folder then my code only get the path to one of the folders and all other folders are ignored. I need a path to the folder just before the .class files and their folders.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论