--
Rajeev Chavan
email to : sschavan at eth dot net
I have lots, but they're all different based upon what I'm sorting. If you
can be more specific, we can give a more specific answer.
I find that if you just keep in mind that multidimensional arrays are simply
"arrays of arrays", things go easier.
--
Ray Marron
Gejza
"Rajeev Chavan" <sschavan...@eth.net> píąe v diskusním příspěvku
news:c21esr$1ne4b0$1...@ID-214544.news.uni-berlin.de...
#include "Directry.ch"
#include "Common.ch"
#include "dll.ch"
#xtranslate .filename => \[1\]
#xtranslate .filesize => \[2\]
#xtranslate .filedate => \[3\]
#xtranslate .filetime => \[4\]
#xtranslate .fileattrib => \[5\]
#xtranslate aDIZ => Stack\[SP,1]
#xtranslate nLEN => Stack\[SP,2]
#xtranslate nCount => Stack\[SP,3]
#xtranslate nStartAt => Stack\[SP,4]
STATIC Stack := {}
STATIC SP := 0
STATIC cDirStart := ""
STATIC aALLFILES := {} // if W98 may be 4096 Limit
PROCEDURE ST_INIT
AADD(Stack,ARRAY(4))
SP++
nStartAt := 1
RETURN
PROCEDURE ST_EXIT
Stack := ASIZE(Stack,--SP)
RETURN
PROCEDURE MAIN(cpar1,cpar2,cpar3,cpar4)
cDirStart := CURDRIVE()+":\"+CURDIR()+"\" // Starting Directory
SET ALTER TO DIREMPTY.BAT // just have a LOG File
SET ALTER ON
RECUDIRS(cDirStart,"*.*",{|x,y|DOWWORK(x,y)}) // ONLY Extension
SET ALTER OFF
SET ALTER TO
RETURN
PROCEDURE RECUDIRS(p_path,p_wildcard,bblock)
ST_INIT() // Init Stack
aDIZ := Directory(p_path+"*.*","D")
nLEN := LEN(aDIZ)
// make all FileNames LOWER()
AEVAL(aDIZ, {|x| x.filename := LOWER(x.filename) })
ASORT(aDIZ,,, {|x,y| x.filename < y.filename})
// First, put all sub-directories
// at the beginning of the list
ASORT(aDIZ,,, {|x,y| "D" $ x.fileattrib })
// Now, lets find out where the other
// files are
AEVAL(aDIZ, {|x,i| nStartAt := ;
IF("D" $ x.fileattrib, i, nStartAt) })
// Sort sub-directories only
ASORT(aDIZ, 1, nStartAt, {|x,y| x.filename < y.filename})
nStartAt++
// Sort only the non-directory files.
// Sort Array based on the first subarray
// element
nLEN := LEN(aDIZ)
* IF nLEN > 1
* ASORT( aDIZ, nStartAt,, {|x,y| CompareFile(x.filename,y.filename) } )
* ASORT( aDIZ, nStartAt,, {|x,y| x.filename < y.filename})
* ENDIF
FOR nCount = 1 to nLEN
IF "D" $ aDIZ[nCount,F_ATTR] .and. .not. ;
(aDIZ[nCount,F_NAME] = "." .or. ;
aDIZ[nCount,F_NAME] ="..")
RECUDIRS(p_path+aDIZ[nCount,F_NAME]+"\",p_wildcard,bblock)
ELSE
EVAL(bblock,p_path,aDIZ[nCount,F_NAME])
ENDIF
NEXT
ST_EXIT() // clear Stack
RETURN
FUNCTION DOWWORK(xPath,bDir)
? xPath,bDir
RETURN NIL
*
* eof
*
greetings by OHR
Jimmy
aOption := ASort(aOption,,,{|x, y| x[1] <= y[1]})
Regards
TSDing
"Rajeev Chavan" <sschavan...@eth.net> wrote in message
news:c21esr$1ne4b0$1...@ID-214544.news.uni-berlin.de...
See Ding's reply for a simple, workable solution.
--
g.
Gary Stark
gst...@RedbacksWeb.com
http://www.RedbacksWeb.com
> This is done in CA-Visual Objects 2.X. Not sure it will work in CA-Clipper
> or not.
>
> aOption := ASort(aOption,,,{|x, y| x[1] <= y[1]})
Yes it will. And there's no need to assign the expression to aOption - only
ASort(...) is enough.
Best regards,
Marcos Nogueira
S. Paulo - Brazil
SET DATE BRIT
aArr := {}
aadd(aArr,{5,ctod("12/2/04")})
aadd(aArr,{2,ctod("15/12/03")})
aadd(aArr,{1,ctod("16/1/04")})
aadd(aArr,{3,ctod("15/12/03")})
aadd(aArr,{6,ctod("15/12/03")})
aadd(aArr,{4,ctod("16/1/04")})
aadd(aArr,{9,ctod("25/12/01")})
aadd(aArr,{7,ctod("15/12/02")})
After sort the array should appear as follows
{9,ctod("25/12/01")}
{7,ctod("15/12/02")}
{2,ctod("15/12/03")}
{3,ctod("15/12/03")}
{6,ctod("15/12/03")}
{1,ctod("16/1/04")}
{4,ctod("16/1/04")}
{5,ctod("12/2/04")}
asort(aArr,,,|x,y| x[2] < y[2])
or
asort(aArr,,,|x,y| x[1] < y[1])
will sort only on one element
AUGE_OHR
Your program I could not understand. It did not run properly. I will have to
look into detail what went wrong
With Best Wishes
Rajeev Chavan
email to : sschavan at eth dot net
>
Rajeev Chavan <sschavan...@eth.net> wrote in message
news:c21esr$1ne4b0$1...@ID-214544.news.uni-berlin.de...
--
_________________________________
Maurizio la Cecilia
Software consultant and Clipper expert
Foggia (Italy)
-----------------------------------------------------------------
"Rajeev Chavan" <sschavan...@eth.net> ha scritto nel messaggio
news:c24tsk$1pf7dc$1...@ID-214544.news.uni-berlin.de...
Regards
TSDing
"Marcos Nogueira" <marcos...@arenainformatica.com.br> wrote in message
news:c24dlg$1olisd$1...@ID-76797.news.uni-berlin.de...
A couple of solutions to choose from:
asort(aArr,,, {|x, y| dtos(x[2])+str(x[1], 3, 0) <= dtos(y[2])+str(y[1], 3,
0)})
asort(aArr,,, {|x, y| x[2] < y[2] .or. (x[2] = y[2] .and. x[1] <= y[1])})
The one with all the conversions to string is probably the slower of the
two, but I didn't test either.
Remember: The code block evaluates to true when the two elements are
already in sorted order!
--
Ray Marron
> What a lot of work!
> See Ding's reply for a simple, workable solution.
Yes, but having a multidimensional array most times you want to sort more
than one time and it is allways not easy to read which element you a just
working with.
this example with Directory() also show some techincs to "subsort" MDA
and like the Name say it can be used recursiv up to 4096x4096 (W98)
elements to sort ...
greetings by OHR
Jimmy
> AUGE_OHR wrote:
> > Example sorting Directory() multidimensional array :
> > compile with -N
> > #include "Directry.ch"
> > #include "Common.ch"
> AUGE_OHR
> Your program I could not understand. It did not run properly. I will have
to
> look into detail what went wrong
exclude the line : #include "dll.ch" (this was Xbase++ for my DowWork() )
and compile with -N switch
greetings by OHR
Jimmy
--
_________________________________
Maurizio la Cecilia
Software consultant and Clipper expert
Foggia (Italy)
-----------------------------------------------------------------
"Maurizio la Cecilia" <m.lac...@vizzavi.it> ha scritto nel messaggio
news:zRn1c.45734$Kc3.1...@twister2.libero.it...