$TYPECHECK ON
'****************************************************************************
'*  QFolder component: scans a folder and all subfolders for files          *
'*                                                                          *
'*  Properties:                                                             *
'*    FolderList: QStringlist object containing all subfolders after a scan *
'*    FileList: QStringlist object containing all files after a scan        *
'*    FolderName: Name of the current scanned file                          *
'*    FileName: Filename of the current scanned file                        *
'*    FileDate: FileDate as string of the current scanned file              *
'*    FileTime: FileTime as string of the current scanned file              *
'*    FileSize: FileSize as integer of the current scanned file             *
'*    FileIntTime: FileTime as integer of the current scanned file          *
'*    SubFolders: Scan all folders if true, Scan only basefolder if false   *
'*                                                                          *
'*  Methods:                                                                *
'*    GetFolderList: start scan operation - stores results in dir/filelist  *
'*    FileCount: returns number of files in FilList (after a scan)          *
'*    FolderCount: returns number of folders in FolderList (after a scan)   *
'*                                                                          *
'*  Events:                                                                 *
'*    OnFileFound: Occurs while scanning when a file is found               *
'*    OnFolderFound: Occurs while scanning when a folder is found           *
'*                                                                          *
'*  Author: Alain Besseleer                                                 *
'*  Version: 1.1                                                            *
'*  Date: November 26, 2005                                                 *
'*                                                                          *
'****************************************************************************


$include "QFolder.inc"

declare sub loaddir
declare sub FileFound
declare sub CancelScan

dim flist as Qfolder
    flist.onFileFound = FileFound
    flist.subfolders = 1

CREATE Form AS QFORM
    Caption = "Subfolder test"
    Width = 667
    Height = 636
    Center
    CREATE RichEdit1 AS QRICHEDIT
        Left = 208
        Top = 8
        Width = 441
        Height = 550
        scrollbars = 2
        HideSelection = 0
    END CREATE
    CREATE DirTree1 as QDIRTREE
        left = 8
        top = 8
        width = 192
        height = 550
        initialdir = "C:"
    END CREATE
    create StartButton as QBUTTON
        caption = "Load selected folder"
        top = 570
        width = 150
        left = 140
        onclick = loaddir
    end create
    create CancelButton as QBUTTON
        caption = "Cancel scan"
        top = 570
        width = 150
        left = 340
        onclick = CancelScan
    end create
END CREATE

sub loaddir
    Form.caption = "Loading filelist with 'OnFileFound' event"
    RichEdit1.clear
    
    if flist.GetFolderList(DirTree1.directory) then  '--> scan complete directory
    
        'save folderlist and filelist to file
        flist.FolderList.savetofile("c:/FolderList.txt")
        flist.filelist.savetofile("c:/filelist.txt")

    else
        showmessage "Directory does not exist"
    end if
    
    Form.Caption = "Subfolder test - " + str$(flist.filecount) + " files found in " _
                   + str$(flist.Foldercount) + " directories."
end sub

sub FileFound
    richedit1.addstrings (flist.filedate + "  " + flist.filetime + "  " + flist.FileName)
end sub

sub CancelScan
    flist.CancelOperation = 1
end sub

form.showmodal
