2010-08-05 67 views

回答

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 
+0

與最近版本的艾菲爾,我會推薦使用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 2014-01-09 13:30:58

2

與最新版本的艾菲爾的,我會建議使用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,這是有幫助的遞歸迭代對目錄