Re: Help needed with walk_dir()
- Posted by hacker Aug 03, 2010
- 1145 views
Thanks Derek and Jim, this is great!
I actually found an example on the old forum, posted by Pete Eberlein.
include sort.e include file.e function by_date(sequence file1, sequence file2) -- compare two files by date, for custom_sort return compare(file1[D_YEAR..D_SECOND], file2[D_YEAR..D_SECOND]) end function function dir_oldest_first(sequence path) -- Custom directory sorting function for walk_dir(). object d d = dir(path) if atom(d) then return d end if return custom_sort(routine_id("by_date"), d) end function my_dir = routine_id("dir_oldest_first") -- for walk_dir function process(sequence path, sequence dirinfo) path = dirinfo[1..1] & reverse(dirinfo[4..6]) & dirinfo[7..9] printf(1,"%s %02d/%02d/%04d %02d:%02d:%02d\n", path) return 0 -- carry on end function if walk_dir(".", routine_id("process"), 0) then puts(1, "walk_dir error") end if
Problem is, I don't really understand how it works, I'll have to trace through the code a few times. I've never really got my head around routine_id() and functions like call_back(), what I really need is a sort of dummies guide to "advanced" euphoria programming.
I'm using version 3.1.1, I notice that in the ver 4.0 example walk_dir() has 4 parameters and not 3...