使用Ruby查找在树上找到最新的文件名

发布于 2025-02-09 21:09:11 字数 142 浏览 1 评论 0原文

我有一棵很大的树。我想搜索带有特定基本文件名的最后一个修改的文件。
IE,有很多具有相同basename的文件,我只想进行最后的修改。我想(有效地),最后一个修改的
IE,求程目录,首先通过修改日期(最新第一个)。我找不到任何find.找到方法。

I have a very large tree. I want to search for the last modified file, with a specific base file name.
I.e., there are many files with the same basename, and I just want the last modified. I want to find (efficiently), the last modified
I.e., Recourse directories, depth first, then, by modify date (latest first). I could not find anything using Find.find how to do it.

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

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

发布评论

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

评论(1

吻泪 2025-02-16 21:09:11

我会这样做:

Dir.glob('path/**/*')                # all files below `path/`
   .select { |f| File.file?(f) }     # exclude folders
   .max_by { |f| File.mtime(f) }     # pick file by maximum modification date

I would do this:

Dir.glob('path/**/*')                # all files below `path/`
   .select { |f| File.file?(f) }     # exclude folders
   .max_by { |f| File.mtime(f) }     # pick file by maximum modification date
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文