1. Walk_Dir and a modified returned order
- Posted by Jay <jgbetzold at yahoo.com> Mar 07, 2005
- 461 views
I'm trying to get my head around this but it really hurts. According to the ref manual.... "By default, the files and subdirectories will be visited in alphabetical order. To use a different order, set the global integer my_dir to the routine id of your own modified dir() function that sorts the directory entries differently. See the default dir() function in file.e." I believe it, I just can't figure out how to do it. I've looked over file.e found the my_dir, searched for hours through the EUforum, went to many mentioned files in the archive and looked them over. I'm way confused. So... Why is my_dir set to -2 bty default? Does that direct a call to the winAPI? To point to my own custom dir() do I have to right a function that mimics the regular dir() and then add coding to change the order of the returned sequence? If so I'm afraid that's way out beyond my limits. What I want is to have the sorted order of the directory I read com back with the oldest file first and then progressively the next newest and so on. So put another way, I want to "walk" thru the directory oldest to newest and then (with code I've already written) process each file in the directory as I go. Can anybody shed some light on my poor mind? Thanks much.
2. Re: Walk_Dir and a modified returned order
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Mar 07, 2005
- 449 views
On Mon, 07 Mar 2005 06:11:33 -0800, Jay <guest at RapidEuphoria.com> wrote: >Why is my_dir set to -2 by default? An illegal value that walk_dir can explicitly test for, which is not likely to be confused with a -1 (undefined) error from routine_id. > >To point to my own custom dir() do I have to right a function that mimics >the regular dir() and then add coding to change the order of the returned > sequence? If so I'm afraid that's way out beyond my limits. > >What I want is to have the sorted order of the directory I read com back >with the oldest file first and then progressively the next newest and so on. OK, here is a complete example:
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
Regards, Pete
3. Re: Walk_Dir and a modified returned order
- Posted by Jay <jgbetzold at yahoo.com> Mar 07, 2005
- 452 views
Than you so much Pete, I went through what you wrote line by line and am begining to understand it. It works flawlessly of course. It's important for me to understand it though and I believe I do. Thanks again.