sort Filename (Extension)

sort Filename (Extension)

Postby Jimmy » Sat Apr 15, 2023 5:01 pm

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:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: sort Filename (Extension)

Postby Natter » Sat Apr 15, 2023 5:39 pm

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
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: sort Filename (Extension)

Postby Jimmy » Sat Apr 15, 2023 6:03 pm

hi,

thx for Answer

now CDX is behind BAT and before DBF
Image

what i like to have is
*.C
*.CDX
*.CH
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: sort Filename (Extension)

Postby Jimmy » Sat Apr 15, 2023 6:19 pm

hi,

i have use Idea of PAD but use PADR()
Image
now it display like i want, thx
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: sort Filename (Extension)

Postby nageswaragunupudi » Sun Apr 16, 2023 12:47 pm

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 } )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: sort Filename (Extension)

Postby nageswaragunupudi » Sun Apr 16, 2023 12:53 pm

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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: sort Filename (Extension)

Postby Jimmy » Mon Apr 17, 2023 6:16 am

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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 65 guests