Re: Walk_Dir and a modified returned order

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu