Page 1 of 1

sort Filename (Extension)

PostPosted: Sat Apr 15, 2023 5:01 pm
by Jimmy
hi,

i do "sort" Result of Directory() but it is not correct with Extension
Image
Code: Select all  Expand view
  CASE nCol = LV_NAME
      IF ::SortOrder = LVS_SORTASCENDING
         ASORT( aDirOut, nStartAt + 1,, { | x, y | ( UPPER( x[ LV_NAME ] ), UPPER( y[ LV_NAME ] ), .T. ) } )

   CASE nCol = LV_EXT
      IF ::SortOrder = LVS_SORTASCENDING
         ASORT( aDirOut, nStartAt + 1,, { | x, y | ( x[ LV_EXT ] + UPPER( x[ LV_NAME ] ) ) < ( y[ LV_EXT ] + UPPER( y[ LV_NAME ] ) ) } )
 


as you can "see" CDX is between C
how to change sort :idea:

Re: sort Filename (Extension)

PostPosted: Sat Apr 15, 2023 5:39 pm
by Natter
For example so:
Code: Select all  Expand view
dim:=directoty("*.*")
ASORT( dim, ,, { | xx,y y | ( padl(UPPER(cFileExt(xx[1] )),5) < padl(UPPER( cFileExt(yy[1] ) ),5) } )


Or you can compare CRC file extensions

Re: sort Filename (Extension)

PostPosted: Sat Apr 15, 2023 6:03 pm
by Jimmy
hi,

thx for Answer

now CDX is behind BAT and before DBF
Image

what i like to have is
*.C
*.CDX
*.CH

Re: sort Filename (Extension)

PostPosted: Sat Apr 15, 2023 6:19 pm
by Jimmy
hi,

i have use Idea of PAD but use PADR()
Image
now it display like i want, thx

Re: sort Filename (Extension)

PostPosted: Sun Apr 16, 2023 12:47 pm
by nageswaragunupudi
PADR is not at all necessary.

Can try:
Code: Select all  Expand view
  ? ASort( { "CDX", "c", "Cpp", "cH" },,,;
      { |x,y| LOWER( X ) < LOWER( y ) } )
 


For case insensitive comparisons, we recommend using
Code: Select all  Expand view

FW_Stricmp( c1, c2 ) // --> -2, -1, 0, 1, 2
 


Incidentally, this function Data Type safe also.

The above function can be written as:
Code: Select all  Expand view
  ? ASort( { "CDX", "c", "Cpp", "cH" },,,;
      { |x,y| FW_Stricmp( x, y ) < 0 } )
 

Re: sort Filename (Extension)

PostPosted: Sun Apr 16, 2023 12:53 pm
by nageswaragunupudi
And wherever possible, it may be easier to leave the sorting business to xbrowse itself and xbrowse does a good job.
Code: Select all  Expand view
  local aDir  := DIRECTORY( "c:\fwh\samples\*.*" )

   SET DATE FORMAT TO "dd.mm.yyyy"
   SET TIME FORMAT TO "hh:mm:ss"

   AEval( aDir, { |a| a[ 3 ] := FW_AddTime( a[ 3 ], a[ 4 ] ), ;
                  AIns( a, 2, cFileExt( a[ 1 ] ) ), ASize( a, 4 ) } )

   XBROWSER aDir AUTOSORT SETUP ( ;
      oBrw:cHeaders := { "NAME", "EXT", "SIZE", "DATE" }, ;
      oBrw:AutoFit(), ;
      oBrw:SetDarkTheme() )
 


Image

Re: sort Filename (Extension)

PostPosted: Mon Apr 17, 2023 6:16 am
by Jimmy
hi,
nageswaragunupudi wrote:And wherever possible, it may be easier to leave the sorting business to xbrowse itself and xbrowse does a good job.

thx for help

i´m sure it work under Fivewin but i use also HMG or Xbase++
so i always search Solution which i can use for all xBase-Dialect