Snippets

SeanB Check Filelist for duplicates

Created by SeanB last modified
Use Windows.pkg
Use cHtmlHelp.pkg
Use cApplication.pkg
Use cTextEdit.pkg
Use File_dlg.pkg

Object oHtmlHelp is a cHtmlHelp
End_Object

Object oApplication is a cApplication
    Set pbPreserveEnvironment to False
    Set peHelpType to htHtmlHelp
End_Object

Struct tFilelist 
    String sLogicalName 
    String sSearch
    Boolean isDuplicated 
    Integer iPosition 
End_Struct

Use Batchdd.pkg

Object oFilelistChecker is a BusinessProcess
    Property String[] paDuplicateList 
    
    Function CurrentValue Integer iFile Returns tFilelist
        tFilelist flValue
        String sName 
        
        Get_Attribute Df_File_Logical_Name of iFile to sName         
        Move (lowercase(sName)) to flValue.sSearch
        Move sName to flValue.sLogicalName
        Move iFile to flValue.iPosition
        Function_Return flValue
    End_Function
    
    Function filelist_sort tFilelist flist1 tFilelist flist2 Returns Integer 
        If (flist1.sSearch>flist2.sSearch) Function_Return (GT) 
        Else If (flist1.sSearch<flist2.sSearch) Function_Return (LT) 
        Else Function_Return (EQ)
    End_Function
    
   Function FillFilelistArray Returns tFilelist[]
        tFilelist[] FilesList 
        Integer iFile 
        
        Move 0 to iFile                                                  
        Repeat                                                           
            Get_Attribute Df_File_Next_Used of iFile to iFile            
            If (iFile <> 0) Move (CurrentValue(Self,iFile)) to FilesList[SizeOfArray(FilesList)]
        Until (iFile=0)  
        
        Function_Return FilesList
    End_Procedure
    
    Function ShowRepeats tFilelist[] FilesList Returns String[]
        Integer iPos 
        Integer iMax 
        String sError 
        String[] aErrors 
        
        Move (SizeOfArray(FilesList)) to iMax 
        Move (iMax-1) to iMax  //don't need to check last items 
        For iPos from 0 to (iMax-1) 
            If (FilesList[iPos].sSearch=FilesList[iPos+1].sSearch) Begin 
                Move (SFormat("Duplicate name: %1; files %2 and %3",FilesList[iPos].sLogicalName,FilesList[iPos].iPosition,FilesList[iPos+1].iPosition)) to sError 
                Move sError to aErrors[SizeOfArray(aErrors)]
            End
        Loop
        Function_Return aErrors
    End_Function
    
    Procedure doProcess 
        tFilelist[] FilesList
        
        Get FillFilelistArray to FilesList
        Move (SortArray(FilesList,Self,get_filelist_sort)) to FilesList
        Set paDuplicateList to (ShowRepeats(Self,FilesList))
    End_Procedure
    
End_Object

Object Main is a ModalPanel 
    Set Size to 173 235
    Set Label to "Search Filelist for duplicates"
    Set Border_Style to Border_Thick
    
    Procedure CheckForDuplicates
        String sValue 
        String[] aDetail 
        Integer iPos 
        Integer iMax 
        String sFilename 
        Boolean isOK 
        
        Send Delete_Data to txtDetails

        Get Value of frmFileList to sFilename 
        File_Exist sFilename isOK 
        If (not(isOK)) Procedure_Return 
        
        Set_Attribute DF_FILELIST_NAME to sFilename 
        Send AppendTextLn to txtDetails "Checking for duplicates"
        
        Send DoProcess to oFilelistChecker
        Get paDuplicateList of oFilelistChecker to aDetail 

        Move (SizeOfArray(aDetail)) to iMax 
        If (iMax = 0) Send AppendTextLn to txtDetails "No Duplicates Found" 
        For iPos from 0 to (iMax-1)
            Send AppendTextLn to txtDetails (aDetail[iPos])         
        Loop
        Send AppendTextLn to txtDetails "Finished" 
    End_Procedure

    Object frmFileList is a Form
        Set Size to 13 132
        Set Location to 11 69
        Set Label to "FileList location"
        Set peAnchors to anLeftRight
    End_Object

    Object btnSearch is a Button
        Set Size to 14 21
        Set Location to 10 202
        Set Label to '...'
        Set peAnchors to anRight
    
        // fires when the button is clicked
        Procedure OnClick
            String[] aSelectedFiles
            Boolean bOpen 
            Get Show_Dialog of oOpenDialog1 to bOpen
            If (bOpen) Begin 
                Get Selected_Files of oOpenDialog1 to aSelectedFiles
                If ((SizeOfArray(aSelectedFiles))<>0) Set Value of frmFileList to aSelectedFiles[0]
            End
            
        End_Procedure
    
    End_Object

    Object btnGo is a Button
        Set Location to 28 68
        Set Label to 'Go'
    
        // fires when the button is clicked
        Procedure OnClick
            Send CheckForDuplicates
        End_Procedure
    
    End_Object

    Object txtDetails is a cTextEdit
        Set Size to 102 219
        Set Location to 49 9
        
        Set peAnchors to anAll
    End_Object

    Object oOpenDialog1 is an OpenDialog
        Set Filter_String to 'filelist|filelist.cfg'
        Set Initial_Folder to 'C:\'
        Set Filter_Index to 2
    End_Object

    
End_Object
Start_UI Main 

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.