|
of_sortdirlist
|
|
Full name
|
pfc_n_cst_filesrv.of_sortdirlist
|
Access
|
public
|
Extend of
|
integer
|
Return value
|
integer
|
Prototype
|
public function integer of_sortdirlist(ref n_cst_dirattrib[],integer,boolean)
|
Name
|
Datatype
|
lds_files
|
n_ds
|
li_rc
|
integer
|
ll_Cnt
|
long
|
ll_Limit
|
long
|
ll_Pos
|
long
|
ll_rowcount
|
long
|
lnv_DirEntry
|
n_cst_dirattrib
|
lnv_empty
|
n_cst_dirattrib[]
|
ls_ascending
|
string
|
ls_sort
|
string
|
ls_sortfilename
|
string
|
public function integer of_sortdirlist (ref n_cst_dirattrib anv_dirlist[], integer ai_sorttype, boolean ab_ascending);//////////////////////////////////////////////////////////////////////////////
// Public Function: of_SortDirList
// Arguments: anv_DirList[] The output structure from the of_DirList function.
// ai_SortType Sort by: 1 - File Name, 2 - File Ext.,
// 3 - File Last Write Date/Time,
// 4 - File Size.
// ab_Ascending True - sort ascending,
// False - sort in descending order.
// Returns: Integer
// 1 if it succeeds and -1 if an error occurs.
// Description: Sort the directory list from the of_DirList function.
//////////////////////////////////////////////////////////////////////////////
// Rev. History: Version
// 5.0 Initial version
// 5.0.03 Changed code to use datastore to perform sorting of directory array.
// 6.0.01 Add destroy of datastore
// 7.0 Change datatypes from int to long
//////////////////////////////////////////////////////////////////////////////
// Copyright © 1996-1999 Sybase, Inc. and its subsidiaries. All rights reserved. Any distribution of the
// PowerBuilder Foundation Classes (PFC) source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//////////////////////////////////////////////////////////////////////////////
integer li_rc
long ll_rowcount, ll_Limit, ll_Cnt, ll_Pos
string ls_sort, ls_ascending, ls_sortfilename
n_cst_dirattrib lnv_DirEntry, lnv_empty[]
n_ds lds_files
// check arguments.
If IsNull(ai_sorttype) or IsNull(ab_ascending) Then Return -1
lds_files = Create n_ds
lds_files.DataObject = "d_dirattrib"
li_rc = lds_files.of_setbase(true)
if li_rc < 0 then
destroy lds_files
return -1
End if
// load datastore
ll_limit = upperbound(anv_dirlist)
for ll_cnt = 1 to ll_limit
lnv_direntry = anv_dirlist[ll_cnt]
If anv_DirList[ll_Cnt].ib_Subdirectory Then
ls_sortfilename = Mid(lnv_direntry.is_FileName, 2, (Len(lnv_direntry.is_FileName) - 2))
of_DirAttribToDS(lds_files, lnv_direntry, ls_sortfilename, 0)
ElseIf anv_DirList[ll_Cnt].ib_Drive Then
ls_sortfilename = Mid(lnv_direntry.is_FileName, 3, 1)
of_DirAttribToDS(lds_files, lnv_direntry, ls_sortfilename, 100)
Else
ls_sortfilename = lnv_direntry.is_FileName
of_DirAttribToDS(lds_files, lnv_direntry, ls_sortfilename, 1)
End If
Next
// sort datastores
if ab_ascending then
ls_ascending = "A"
else
ls_ascending = "D"
end if
// filegroup makes subdirectories appear before files and files before drives
Choose Case ai_SortType
Case 1 // Sort by file name
ls_sort = "filegroup A, sortfilename " + ls_ascending
lds_files.SetSort(ls_sort)
lds_files.Sort()
Case 2 // Sort by file extension
ls_sort = "filegroup A, extension " + ls_ascending
lds_files.SetSort(ls_sort)
lds_files.Sort()
Case 3 // Sort by last write date.
ls_sort = "filegroup A, lastwritedate " + ls_ascending + ", lastwritetime " + ls_ascending
lds_files.SetSort(ls_sort)
lds_files.Sort()
Case 4 // Sort by size
ls_sort = "filegroup A, filesize " + ls_ascending
lds_files.SetSort(ls_sort)
lds_files.Sort()
End Choose
// unload datastores
anv_dirlist = lnv_empty
ll_pos = 1
ll_rowcount = lds_files.rowcount()
for ll_cnt = 1 to ll_rowcount
of_dstodirattrib (lds_files, lnv_direntry, ll_cnt)
anv_dirlist[ll_pos] = lnv_direntry
ll_pos ++
next
destroy lds_files
Return 1
end function