如何遍历eiffel中的目录?

发布于 2024-09-13 02:58:15 字数 41 浏览 6 评论 0原文

简单

如何使用 eiffel 获取目录内文件的列表?

Simple

How can I get a list of the files that are inside directory using eiffel?

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

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

发布评论

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

评论(2

沫雨熙 2024-09-20 02:58:15

例如:


class CARPETAS

creation
    make

feature {NONE}

    make is
      local
          directory: DIRECTORY
          path: STRING
      do
          path := "." -- Current directory
          !!directory.scan_with(path)
          list_directory(directory)
      end

    list_directory(directory: DIRECTORY) is
      local
          i: INTEGER
      do
          std_output.put_string("Content of " + directory.path + "%N")
          from
              i := directory.lower
          until
              i > directory.upper
          loop
              std_output.put_string("%T" + directory.name(i) + "%N")
              i := i + 1
          end
      end
end

For example:


class CARPETAS

creation
    make

feature {NONE}

    make is
      local
          directory: DIRECTORY
          path: STRING
      do
          path := "." -- Current directory
          !!directory.scan_with(path)
          list_directory(directory)
      end

    list_directory(directory: DIRECTORY) is
      local
          i: INTEGER
      do
          std_output.put_string("Content of " + directory.path + "%N")
          from
              i := directory.lower
          until
              i > directory.upper
          loop
              std_output.put_string("%T" + directory.name(i) + "%N")
              i := i + 1
          end
      end
end
苏佲洛 2024-09-20 02:58:15

对于最新版本的 Eiffel,我建议使用 DIRECTORY.entries

local
    p: PATH 
do
    across dir.entries as ic loop
        p := ic.item.path
            -- then use interface of PATH, such as PATH.name 
    end
end

请注意,base_extension 库还提供 DIRECTORY_VISITOR ,这有助于在目录上递归迭代

with recent version of Eiffel, I would recommend to use DIRECTORY.entries

local
    p: PATH 
do
    across dir.entries as ic loop
        p := ic.item.path
            -- then use interface of PATH, such as PATH.name 
    end
end

note that the base_extension library also provides DIRECTORY_VISITOR , which is helpful to iterate recursively on directories

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