elviejo79
elviejo79

Reputation: 4600

How to traverse a directory in eiffel?

Simple

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

Upvotes: 2

Views: 369

Answers (2)

Jocelyn
Jocelyn

Reputation: 703

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

Upvotes: 3

Marcos
Marcos

Reputation: 4643

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

Upvotes: 4

Related Questions