sort Filename (Extension)

Post Reply
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

sort Filename (Extension)

Post by Jimmy »

hi,

i do "sort" Result of Directory() but it is not correct with Extension
Image

Code: Select all | Expand

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

Re: sort Filename (Extension)

Post by Natter »

For example so:

Code: Select all | Expand

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
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: sort Filename (Extension)

Post by Jimmy »

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: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: sort Filename (Extension)

Post by Jimmy »

hi,

i have use Idea of PAD but use PADR()
Image
now it display like i want, thx
greeting,
Jimmy
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: sort Filename (Extension)

Post by nageswaragunupudi »

PADR is not at all necessary.

Can try:

Code: Select all | Expand

   ? ASort( { "CDX", "c", "Cpp", "cH" },,,;
      { |x,y| LOWER( X ) < LOWER( y ) } )
 
For case insensitive comparisons, we recommend using

Code: Select all | Expand

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

   ? ASort( { "CDX", "c", "Cpp", "cH" },,,;
      { |x,y| FW_Stricmp( x, y ) < 0 } )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: sort Filename (Extension)

Post 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

   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
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: sort Filename (Extension)

Post 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
greeting,
Jimmy
Post Reply