简单
如何使用eiffel获取目录内的文件列表?
答案 0 :(得分:3)
例如:
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
答案 1 :(得分: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,这有助于在目录上递归迭代