2

Simple

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

elviejo79
  • 4,592
  • 2
  • 32
  • 35

2 Answers2

4

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
Marcos
  • 4,643
  • 7
  • 33
  • 60
  • 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 – Jocelyn Jan 09 '14 at 13:30
3

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

Jocelyn
  • 693
  • 5
  • 8