【问题标题】:How to traverse a directory in eiffel?如何遍历eiffel中的目录?
【发布时间】:2014-01-09 21:35:30
【问题描述】:

简单

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

【问题讨论】:

    标签: eiffel


    【解决方案1】:

    例如:

    
    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
    

    【讨论】:

    • 对于最新版本的 Eiffel,我建议使用 DIRECTORY.entries local p: PATH do across dir.entries as ic loop p := ic.item.path -- 然后使用接口PATH的,比如PATH.name end end
    【解决方案2】:

    对于最新版本的 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 ,这有助于在目录上递归迭代

    【讨论】:

    • 在哪里可以找到 DIRECTORY_VISITOR 的示例?
    猜你喜欢
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 2010-11-27
    • 2011-06-22
    • 2011-01-07
    • 1970-01-01
    • 2023-03-31
    • 2016-01-22
    相关资源
    最近更新 更多