Re: can i make this better?
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Feb 07, 2004
- 506 views
----- Original Message ----- From: "Greg Haberek" <g.haberek at comcast.net> To: <EUforum at topica.com> Subject: can i make this better? > > > I want to sort the results from dir() so that all the directories are first, > then the files, in alphabetical order. I'm using custom_sort() and > compare(), so far this is what I have: > > function compare_dir(object x1, object x2) > integer ret > > if find('d', x1[D_ATTRIBUTES]) then > if find('d', x2[D_ATTRIBUTES]) then > ret = compare(lower(x1[D_NAME]), lower(x2[D_NAME])) > else > ret = -1 > end if > else > if find('d', x2[D_ATTRIBUTES]) then > ret = 1 > else > ret = compare(lower(x1[D_NAME]), lower(x2[D_NAME])) > end if > end if > > return ret > end function > > function sort_dir(sequence x) > return custom_sort(routine_id("compare_dir"), x) > end function > > > Right now this works, but I feel all those if statements could be more > efficient, it just looks messy to me. Can anyone patch this up? > > ~Greg function compare_dir(object x1, object x2) integer ret integer d1,d2 d1 = (find('d', x1[D_ATTRIBUTES]) != 0) d2 = (find('d', x2[D_ATTRIBUTES]) != 0) if d1 = d2 then ret = compare(lower(x1[D_NAME]), lower(x2[D_NAME])) else ret = d2 - d1 end if return ret end function > > > TOPICA - Start your own email discussion group. FREE! > >