File: n_svc_files.sru
Size: 34639
Date: Mon, 07 Apr 2008 21:31:09 +0200
$PBExportHeader$n_svc_files.sru
$PBExportComments$File Services
forward
global type n_svc_files from n_svc_base
end type
end forward

shared variables
Boolean CANCEL
end variables

global type n_svc_files from n_svc_base
end type
global n_svc_files n_svc_files

type prototypes

end prototypes

type variables
Private:

CONSTANT long MAX_LEN = 255
CONSTANT long CHUNK_32K = 32765
CONSTANT string ALL_FILES = "*.*"
CONSTANT string PATH_SEPARATOR = CString.BACKSLASH
CONSTANT string TMP_EXTENSION = "TMP"
end variables

forward prototypes
public subroutine of_cancel ()
public function string of_compactpath (ref n_svc_mgr anv_svc, readonly dragobject ado, readonly string as_string)
public function string of_getapppath (ref n_svc_mgr anv_svc)
public function string of_fixpath (readonly string as_path)
public function string of_getpath (readonly string as_fullpath)
public function string of_getfilename (string as_fullpath)
public function string of_gettemppath (ref n_svc_mgr anv_svc)
public function string of_createtempfile (ref n_svc_mgr anv_svc, string as_extension)
public function string of_createtempfile (ref n_svc_mgr anv_svc)
public function integer of_fileread (ref n_svc_mgr anv_svc, readonly string as_filename, ref blob ab_read)
public function integer of_filewrite (ref n_svc_mgr anv_svc, readonly string as_filename, readonly blob ab_write)
public function long of_filemove (readonly string as_source, readonly string as_destination)
public function long of_filecopy (readonly string as_sourcefile, readonly string as_destination, readonly boolean ab_replace)
protected function long of_findstart (ref n_svc_mgr anv_svc, readonly string as_pattern, ref win32_find_data astr)
protected function long of_findnext (ref n_svc_mgr anv_svc, readonly long al_fileh, ref win32_find_data astr)
protected function long of_findend (ref n_svc_mgr anv_svc, readonly long al_fileh)
protected function long of_findfile (ref n_svc_mgr anv_svc, readonly string as_pattern, readonly boolean ab_dironly, ref string as_ret[], readonly powerobject apo_callback)
public function long of_dirlist (ref n_svc_mgr anv_svc, readonly string as_path, string as_filter, ref string as_files[], powerobject apo_callback)
public function long of_dirlist (ref n_svc_mgr anv_svc, readonly string as_path, string as_filter, ref string as_files[])
public function long of_dirlist (ref n_svc_mgr anv_svc, readonly string as_path, ref string as_files[], powerobject apo_callback)
public function long of_dirlist (ref n_svc_mgr anv_svc, readonly string as_path, ref string as_files[])
public function long of_filecopy (readonly string as_sourcefile, readonly string as_destination)
public function long of_getdirectories (ref n_svc_mgr anv_svc, readonly string as_path, ref string as_dirs[])
public function long of_search (ref n_svc_mgr anv_svc, string as_path, readonly string as_filter, ref string as_location[], ref string as_filename[], readonly powerobject apo_callback)
public function string of_combinepath (string as_path1, string as_path2)
public function long of_search (ref n_svc_mgr anv_svc, string as_path, readonly string as_filter, ref string as_location[], ref string as_filename[])
public function string of_getseparator ()
public subroutine of_deltree (ref n_svc_mgr anv_svc, readonly string as_path)
end prototypes

public subroutine of_cancel ();//===========================================================================
// Function: of_Cancel (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
CANCEL = TRUE
end subroutine

public function string of_compactpath (ref n_svc_mgr anv_svc, readonly dragobject ado, readonly string as_string);//===========================================================================
// Function: of_Compactpath (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly DragObject ado
//  readonly String as_string
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_win32 lnv_win32
string ls_ret
long ll_h
ulong lul_dc

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

ll_h = Handle(this)
lul_dc = lnv_win32.GetDC(ll_h)
ls_ret = as_string
lnv_win32.PathCompactPath(lul_dc, ls_ret, UnitsToPixels(ado.width, XUnitsToPixels!))
lnv_win32.ReleaseDC(ll_h, lul_dc)

RETURN ls_ret
end function

public function string of_getapppath (ref n_svc_mgr anv_svc);//===========================================================================
// Function: of_Getapppath (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note: This call will only work for the currently running application.
//       If you run it from within PB, it will give you PB's application path.  
//       When you compile and run you application it will return that application's path
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_win32 lnw
string lsf
ulong lul_Handle

lul_Handle = handle(GetApplication()) //get application handle
lsf = Space(MAX_LEN) //pre-allocate buffer

anv_svc.of_loadsvc(lnw, CSvc.WIN32)
lnw.GetModuleFilename (lul_Handle, lsf, MAX_LEN)

RETURN TRIM(lsf)
end function

public function string of_fixpath (readonly string as_path);//===========================================================================
// Function: of_Fixpath (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly String as_path
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
IF RIGHT(as_path, 1) = PATH_SEPARATOR THEN RETURN as_path

RETURN as_path + PATH_SEPARATOR
end function

public function string of_getpath (readonly string as_fullpath);//===========================================================================
// Function: of_Getpath (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly String as_fullpath
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsr

lsr = REVERSE(as_fullpath)

lsr = REVERSE(MID(lsr, POS(lsr, PATH_SEPARATOR) + LEN(PATH_SEPARATOR)))

RETURN of_FixPath(lsr)
end function

public function string of_getfilename (string as_fullpath);//===========================================================================
// Function: of_Getfilename (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  value String as_fullpath
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
IF POS(as_fullpath, PATH_SEPARATOR) <= 0 THEN RETURN as_fullpath

as_fullpath = REVERSE(as_fullpath)
RETURN REVERSE(MID(as_fullpath, 1, POS(as_fullpath, PATH_SEPARATOR) - LEN(PATH_SEPARATOR)))
end function

public function string of_gettemppath (ref n_svc_mgr anv_svc);//===========================================================================
// Function: of_Gettemppath (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_win32 lnv_win32
string ls_ret, ls_tmp

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

ls_tmp = SPACE(MAX_LEN)

IF lnv_win32.GetTempPath(MAX_LEN, ls_tmp) = CRet.NO_ACTION THEN
   RETURN CString.EMPTY
END IF

ls_tmp = TRIM(ls_tmp)
ls_ret = SPACE(MAX_LEN)
lnv_win32.GetLongPathName(ls_tmp, ls_ret, MAX_LEN)

RETURN ls_ret
end function

public function string of_createtempfile (ref n_svc_mgr anv_svc, string as_extension);//===========================================================================
// Function: of_Createtempfile (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  value String as_extension
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_win32 lnv_win32
n_svc_isempty lnv_check
string ls_ret, ls_path, ls_filename

anv_svc.of_LoadSvc(lnv_check, CSvc.ISEMPTY)

IF lnv_check.of_IsEmpty(as_extension) THEN
   as_extension = TMP_EXTENSION
END IF

ls_ret = SPACE(MAX_LEN)

ls_path = of_GetTempPath(anv_svc)
lnv_win32.GetTempFilename(ls_path, as_extension, 0, ls_ret)

RETURN TRIM(ls_ret)

end function

public function string of_createtempfile (ref n_svc_mgr anv_svc);//===========================================================================
// Function: of_Createtempfile (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN of_createtempfile(anv_svc, CString.EMPTY)
end function

public function integer of_fileread (ref n_svc_mgr anv_svc, readonly string as_filename, ref blob ab_read);//===========================================================================
// Function: of_Fileread (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_filename
//  reference Blob ab_read
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
long ll_flen, ll_file, ll_loops, i, llr
blob lb_temp
n_svc_isempty lnv_check

anv_svc.of_LoadSvc(lnv_check, CSvc.ISEMPTY)

IF lnv_check.of_IsEmpty(as_filename) OR NOT FileExists(as_filename) THEN 
   RETURN CRet.FAILURE
ELSE
   ll_flen = FileLength(as_filename)
   ll_file = FileOpen(as_filename, StreamMode!, Read!, LockRead!)
      
   IF ll_file = CRet.FAILURE THEN 
      FileClose(ll_file)
      RETURN CRet.FAILURE
   ELSE
      IF ll_flen > CHUNK_32K THEN
         IF Mod(ll_flen, CHUNK_32K) = 0 THEN
            ll_loops = ll_flen/CHUNK_32K
         ELSE
            ll_loops = (ll_flen/CHUNK_32K) + 1
         END IF
      ELSE
         ll_loops = 1
      END IF   
      
      FOR i = 1 to ll_loops
         IF FileRead(ll_file, lb_temp) = CRet.FAILURE THEN
            FileClose(ll_file)
            RETURN Cret.FAILURE
         END IF
         ab_read += lb_temp
      NEXT        
   END IF
   
   FileClose(ll_file)
END IF

RETURN CRet.SUCCESS
end function

public function integer of_filewrite (ref n_svc_mgr anv_svc, readonly string as_filename, readonly blob ab_write);//===========================================================================
// Function: of_Filewrite (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_filename
//  readonly Blob ab_write
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
blob  lbr
long i, loops , n, lfh
string lsm

IF LEN(ab_write) > 0 AND NOT ISNULL(ab_write) THEN
   
   //delete file
   IF FileExists(as_filename) THEN FileDelete(as_filename)
   
   IF LEN(ab_write) > CHUNK_32K THEN
      lfh = FileOpen(as_filename, StreamMode!, Write!, Shared!, Replace!)
      IF lfh <> CRet.FAILURE THEN
         IF Mod(LEN(ab_write), CHUNK_32K) = 0 THEN
            loops = LEN(ab_write) / CHUNK_32K
         ELSE
            loops = (LEN(ab_write) / CHUNK_32K) + 1
         END IF
         FOR i = 1 to loops
            lbr = BLOBMID(ab_write, n, CHUNK_32K)
            IF FileWrite(lfh, lbr) = CRet.FAILURE THEN
               FileClose(lfh)
               RETURN CRet.FAILURE
            END IF
            n = i * CHUNK_32K
            n += 1
         NEXT
         FileClose(lfh)
      ELSE
         FileClose(lfh)
         RETURN CRet.FAILURE
      END IF
   ELSE
      lfh = FileOpen(as_filename, StreamMode!, Write!, Shared!, Replace!)
      IF lfh <> CRet.FAILURE  THEN
         IF FileWrite(lfh, ab_write) = CRet.FAILURE THEN
            FileClose(lfh)
            RETURN CRet.FAILURE
         END IF
      ELSE
         FileClose(lfh)
         RETURN CRet.FAILURE        
      END IF
      
      FileClose(lfh)
   END IF
END IF

RETURN CRet.SUCCESS
end function

public function long of_filemove (readonly string as_source, readonly string as_destination);//===========================================================================
// Function: of_Filemove (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly String as_source
//  readonly String as_destination
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN FileMove(as_source, as_destination)
end function

public function long of_filecopy (readonly string as_sourcefile, readonly string as_destination, readonly boolean ab_replace);//===========================================================================
// Function: of_Filecopy (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly String as_sourcefile
//  readonly String as_destination
//  readonly Boolean ab_replace
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN FileCopy(as_sourcefile, as_destination, ab_replace)
end function

protected function long of_findstart (ref n_svc_mgr anv_svc, readonly string as_pattern, ref win32_find_data astr);//===========================================================================
// Function: of_Findstart (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_pattern
//  reference win32_find_data astr
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_win32 lnv_win32
win32_find_data lstr
long lh

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

lh = lnv_win32.FindFirstFile(as_pattern, lstr)
IF lh < 0 THEN
   RETURN CRet.FAILURE
ELSE
   astr = lstr
END IF

RETURN lh
end function

protected function long of_findnext (ref n_svc_mgr anv_svc, readonly long al_fileh, ref win32_find_data astr);//===========================================================================
// Function: of_Findnext (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly Long al_fileh
//  reference win32_find_data astr
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_win32 lnv_win32
win32_find_data lstr
long lrc

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

lrc = lnv_win32.FindNextFile(al_fileh, astr)

IF lrc <= 0 THEN
   //astr = lstr
   lrc = CRet.FAILURE
END IF

RETURN lrc
end function

protected function long of_findend (ref n_svc_mgr anv_svc, readonly long al_fileh);//===========================================================================
// Function: of_Findend (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly Long al_fileh
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_win32 lnv_win32

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)

RETURN lnv_win32.FindClose(al_fileh)
end function

protected function long of_findfile (ref n_svc_mgr anv_svc, readonly string as_pattern, readonly boolean ab_dironly, ref string as_ret[], readonly powerobject apo_callback);//===========================================================================
// Function: of_Findfile (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_pattern
//  readonly Boolean ab_dironly
//  reference String as_ret[]
//  readonly PowerObject apo_callback
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_filename
long c, lfh
win32_find_data lstr
n_svc_bit lnv_bit

IF CANCEL THEN RETURN c

c = UPPERBOUND(as_ret)

lfh = of_FindStart(anv_svc, as_pattern, lstr)

IF lfh <= 0 THEN
   of_FindEnd(anv_svc, lfh)
   RETURN CRet.FAILURE
END IF

anv_svc.of_LoadSvc(lnv_bit, CSvc.BIT)

DO WHILE lfh > 0
   ls_filename = lstr.filename
   
   IF TRIM(ls_filename) <> ".." AND TRIM(ls_filename) <> "." THEN
      IF ab_dironly THEN
         IF lnv_bit.of_bitwiseand ( {lstr.fileattributes,  CWin32.FILE_ATTRIBUTE_DIRECTORY}) = CWin32.FILE_ATTRIBUTE_DIRECTORY THEN
            c++
            as_ret[c] = ls_filename
         END IF
      ELSE
         IF lnv_bit.of_bitwiseand ( {lstr.fileattributes,  CWin32.FILE_ATTRIBUTE_DIRECTORY}) <> CWin32.FILE_ATTRIBUTE_DIRECTORY THEN
            c++
            as_ret[c] = ls_filename
         END IF
      END IF
   END IF
   IF of_FindNext(anv_svc, lfh, lstr) = CRet.FAILURE THEN EXIT
LOOP

IF lfh <> 0 THEN
   of_FindEnd(anv_svc, lfh)
END IF

RETURN c
end function

public function long of_dirlist (ref n_svc_mgr anv_svc, readonly string as_path, string as_filter, ref string as_files[], powerobject apo_callback);//===========================================================================
// Function: of_Dirlist (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_path
//  value String as_filter
//  reference String as_files[]
//  value PowerObject apo_callback
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_isempty lnv_check

anv_svc.of_LoadSvc(lnv_check, CSvc.ISEMPTY)

IF lnv_check.of_IsEmpty(as_filter) THEN as_filter = ALL_FILES

RETURN of_FindFile(anv_svc, of_FixPath(as_path) + as_filter, FALSE, as_files, apo_callback)
end function

public function long of_dirlist (ref n_svc_mgr anv_svc, readonly string as_path, string as_filter, ref string as_files[]);//===========================================================================
// Function: of_Dirlist (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_path
//  value String as_filter
//  reference String as_files[]
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
powerobject lpo

//pass dummy callback object
RETURN of_DirList(anv_svc, as_path, as_filter, as_files, lpo)
end function

public function long of_dirlist (ref n_svc_mgr anv_svc, readonly string as_path, ref string as_files[], powerobject apo_callback);//===========================================================================
// Function: of_Dirlist (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_path
//  reference String as_files[]
//  value PowerObject apo_callback
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
//list all
RETURN of_DirList(anv_svc, as_path, ALL_FILES, as_files, apo_callback)
end function

public function long of_dirlist (ref n_svc_mgr anv_svc, readonly string as_path, ref string as_files[]);//===========================================================================
// Function: of_Dirlist (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_path
//  reference String as_files[]
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
powerobject lpo
//list all, pass dummy callback
RETURN of_DirList(anv_svc, as_path, ALL_FILES, as_files, lpo)
end function

public function long of_filecopy (readonly string as_sourcefile, readonly string as_destination);//===========================================================================
// Function: of_Filecopy (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly String as_sourcefile
//  readonly String as_destination
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN of_FileCopy(as_sourcefile, as_destination, FALSE)
end function

public function long of_getdirectories (ref n_svc_mgr anv_svc, readonly string as_path, ref string as_dirs[]);//===========================================================================
// Function: of_Getdirectories (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_path
//  reference String as_dirs[]
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
powerobject lpo

//pass dummy callback, set to directory only
RETURN of_FindFile(anv_svc, of_CombinePath(as_path, ALL_FILES), TRUE, as_dirs, lpo)
end function

public function long of_search (ref n_svc_mgr anv_svc, string as_path, readonly string as_filter, ref string as_location[], ref string as_filename[], readonly powerobject apo_callback);//===========================================================================
// Function: of_Search (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  value String as_path
//  readonly String as_filter
//  reference String as_location[]
//  reference String as_filename[]
//  readonly PowerObject apo_callback
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_files[], ls_dirs[]
long lc, n, lu

//reset cancel
CANCEL = FALSE

as_path = of_Fixpath(as_path)

//trigger callback
IF ISVALID(apo_callback) THEN &
   apo_callback.TriggerEvent(CKevents.FILESEARCH_CALLBACK)

//search for files
of_DirList(anv_svc, as_path, as_filter, ls_files, apo_callback)

lc = UPPERBOUND(ls_files)
lu = UPPERBOUND(as_filename)
FOR n = 1 to lc
   as_location[lu + n] = as_path
   as_filename[lu + n] = ls_files[n]
NEXT

//get subdirs
of_GetDirectories(anv_svc, as_path, ls_dirs)
lc = UPPERBOUND(ls_dirs)
FOR n = 1 to lc
   IF CANCEL THEN EXIT
   //recurse
   of_Search(anv_svc, of_CombinePath(as_path, ls_dirs[n]), as_filter, as_location, as_filename, apo_callback)
NEXT

RETURN UPPERBOUND(as_filename)
end function

public function string of_combinepath (string as_path1, string as_path2);//===========================================================================
// Function: of_Combinepath (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  value String as_path1
//  value String as_path2
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
as_path1 = of_FixPath(as_path1)

IF LEFT(as_path2, 1) = PATH_SEPARATOR THEN
   as_path2 = MID(as_path2, 2)
END IF

RETURN as_path1 + as_path2
end function

public function long of_search (ref n_svc_mgr anv_svc, string as_path, readonly string as_filter, ref string as_location[], ref string as_filename[]);//===========================================================================
// Function: of_Search (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  value String as_path
//  readonly String as_filter
//  reference String as_location[]
//  reference String as_filename[]
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
powerobject lpo_dummy

RETURN of_Search(anv_svc, as_path, as_filter, as_location, as_filename, lpo_dummy)
end function

public function string of_getseparator ();//===========================================================================
// Function: of_Getseparator (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN PATH_SEPARATOR
end function

public subroutine of_deltree (ref n_svc_mgr anv_svc, readonly string as_path);//===========================================================================
// Function: of_Deltree (public )
// Object: n_svc_files
//---------------------------------------------------------------------------
// Description:
// Note: Deletes a directory including all the files and sub-directories
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_path
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_dirs[], ls_files[], ls_fullpath, ls_dirpath
long ll_count, n

ll_count = of_getdirectories(anv_svc, as_path, ls_dirs)
FOR n = 1 to ll_count
   //recurse
   of_DelTree(anv_svc, of_CombinePath(as_path, ls_dirs[n]))
NEXT

ll_count = of_dirlist(anv_svc, as_path, ls_files)
FOR n = 1 to ll_count
   ls_fullpath = of_CombinePath(as_path, ls_files[n])
   IF FileExists(ls_fullpath) THEN FileDelete(ls_fullpath)
NEXT

RemoveDirectory(as_path)
end subroutine

on n_svc_files.create
call super::create
end on

on n_svc_files.destroy
call super::destroy
end on