Jump to content

_FileListToArrayRec() How to find the right files?


Recommended Posts

Im working on a script to find files in a download folder that belong together like a set if you will

#include <APIConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
#include <File.au3> ; For Pathsplit
; ---------------------------------
Global $g_aDropFiles[0] ; Internal array, DO NOT USE directly. Instead call GetDropFiles() & IsValidDrop()
; ---------------------------------
$sArchiveExt = '.par2|.par3'
$sArchiveExt &= '.rar|.001|.zip|.7z'
$sArchiveExt &= '.nfo|.sfv|.nzb'
$sArchiveExt &= '.r00|.r01'
Local $ExtTypes = StringSplit($sArchiveExt, "|") ; Support for upto 300 deep rar archives


StartGui()

Func StartGui()
    Local $hGUI = GUICreate('', 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)
    Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
    If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_DROPFILES, $MSGFLT_ALLOW) ; IMPORTANT: If the system is using limited access rights
    If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW) ; IMPORTANT: If the system is using limited access rights
    ; ---------------------------------
    GUICtrlCreateLabel('', 0, 0, 500, 500) ; Create a label that is transparent which will accept 'drop' events.
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetResizing(-1, $GUI_DOCKALL)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')
    GUISetState(@SW_SHOW, $hGUI)
    Local $aDropped = 0
    ; ---------------------------------
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $GUI_EVENT_DROPPED
                $aDropped = GetDropFiles() ; This always returns a valid array regardless of an error
                If IsValidDrop() Then ; Was a valid drop?
                    _ArraySort($aDropped); Sort the array so the first file is at the top
                    _ArrayDisplay($aDropped) ; <<<<<<<<<< error checking
                    $FirstFile = $aDropped[1]; Select only the first file for the name
                    $FileSplit = _PathSplit($FirstFile, $sDrive, $sDir, $sFilename, $sExtension) ; split the name from the path
                    $sPath = $sDrive & $sDir
                    ConsoleWrite('Path = ' & $sPath & @CRLF)
                    ConsoleWrite('Drive = ' & $sDrive & @CRLF & 'Dir = ' & $sDir & @CRLF & 'Filename = ' & $sFilename & @CRLF & 'Extension = ' & $sExtension & @CRLF) ; <<<<<<<<<< error checking
                    ;----------------------------------------
                    For $i = 1 To $ExtTypes[0]
                        Local $FindFiles = _FileListToArrayRec($sPath, '*' & StringTrimLeft($sFilename, 7) & '*', 1, 0)
                        _ArrayDisplay($FindFiles, "Files")
                        If IsArray($FindFiles) Then
                            For $i = 1 To $FindFiles[0]
                                FileMove($sPath & $FindFiles[$i], $sPath & $sFilename & "\", 9)
                                Sleep(100)
                            Next
                        EndIf
                    Next
                    ;----------------------------------------
                Else
                    MsgBox(64, 'File Error', 'Unknown Archive File Type')
                EndIf
                ConsoleWrite(@CRLF) ; Empty line
        EndSwitch
    WEnd
    GUIDelete($hGUI) ; Clean up the resources
EndFunc   ;==>StartGui


; Get the dropped list of files. NOTE: Destroys the global varibale on return
Func GetDropFiles()
    Local Const $aEmpty[1] = [0] ; Empty array
    Local $aReturn = $g_aDropFiles
    $g_aDropFiles = $aEmpty ; Destroy the global variable with the empty array
    Return $aReturn
EndFunc   ;==>GetDropFiles

; Use to determine if the drop was valid
Func IsValidDrop()
    Return UBound($g_aDropFiles) > 0
EndFunc   ;==>IsValidDrop

Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $lParam
    If $iMsg = $WM_DROPFILES Then
        $g_aDropFiles = _WinAPI_DragQueryFileEx($wParam)
        If Not UBound($g_aDropFiles) Then
            Local Const $aError[1] = [0] ; Empty array
            $g_aDropFiles = $aError ; Set with the empty array
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES

The problem is this

For $i = 1 To $ExtTypes[0] ; Find if there is more than one set
                        Local $FindFiles = _FileListToArrayRec($sPath, '*' & StringTrimLeft($sFilename, 7) & '*', 1, 0)
                        _ArrayDisplay($FindFiles, "Files")
                        If IsArray($FindFiles) Then
                            For $i = 1 To $FindFiles[0]
                                FileMove($sPath & $FindFiles[$i], $sPath & $sFilename & "\", 9)
                                Sleep(100)
                            Next
                        EndIf
                    Next

I cant think of any way to do this part StringTrimLeft($sFilename, 7) so that it removes enough of the file ending so that all files will be found because they have the same name

Long Filemame With No Usuable Chars78 is fine but other files in the set maybe different like this
Long Filemame With No Usuable Chars78.vol00+01 just about works but would miss the earlier file
tapcla02 can work but 7 chars makes it clash with other files sometimes
413529af4de5db32dd88963aaf177729.vol07+8 can be ok as well
k8NXnJs_8ZF8wk6qsoK.part06 works fine

Really Long Filename.v1.40.208-TEST for eg would work but would miss this following file
Really Long Filename.v1.40

Ive tried different amounts for the trim but i keep finding files that dont work and then it misses them

Is there a way to remove enough of the file ending to be able to safely compare the file against other files in the same folder?, maybe the end numbers with the addition of the word vol and/or part maybe?

Or a different way to distinguish many files in a folder amongst other files

Link to comment
Share on other sites

  • Moderators

Chimaera,

Can you please post a representative file list showing which files you want selected and which you want excluded - and which of the files you are using as the _FileListToArrayRec filter template after the _PathSplit operation. That should allow the development of a suitable pattern - I am afraid your description above of the various possibilities is rather confused.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

To tack onto what @Melba23 said, don't declare variables inside loops, as it's hinders performance.

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Chimaera,

Based on the file list you PMed me, this function seems to work quite well - if I have correctly guessed the members of each family:

#include <Array.au3>

Global $aList[] = [25, _
        "####### 12 v12.0.00800 MultiLingual Genial78.par2", _
        "#######  12 v12.0.00800 MultiLingual Genial78.part1.rar", _
        "#######  12 v12.0.00800 MultiLingual Genial78.part2.rar", _
        "#######  12 v12.0.00800 MultiLingual Genial78.part3.rar", _
        "#######  12 v12.0.00800 MultiLingual Genial78.vol00+01.PAR2", _
        "#######  12 v12.0.00800 MultiLingual Genial78.vol01+02.PAR2", _
        "#######  12 v12.0.00800 MultiLingual Genial78.vol03+04.PAR2", _
        "#######  12 v12.0.00800 MultiLingual Genial78.vol07+08.PAR2", _
        "#######  12 v12.0.00800 MultiLingual Genial78.vol15+13.PAR2", _
        "~~~~~~~.v.1.40.208-TE.nfo", _
        "~~~~~~~.v.1.40.208-TE.r00", _
        "~~~~~~~.v.1.40.208-TE.r01", _
        "~~~~~~~.v.1.40.208-TE.r02", _
        "~~~~~~~.v.1.40.208-TE.r03", _
        "~~~~~~~.v.1.40.208-TE.r04", _
        "~~~~~~~.v.1.40.208-TE.r05", _
        "~~~~~~~.v.1.40.208-TE.r06", _
        "~~~~~~~.v.1.40.208-TE.rar", _
        "~~~~~~~.v.1.40.nzb", _
        "~~~~~~~.v.1.40.par2", _
        "~~~~~~~.v.1.40.sfv", _
        "~~~~~~~.v.1.40.vol00+1.PAR2", _
        "~~~~~~~.v.1.40.vol01+2.PAR2", _
        "~~~~~~~.v.1.40.vol03+4.PAR2", _
        "~~~~~~~.v.1.40.vol07+6.PAR2"]

; Loop through the list to test each element individually
For $i = 1 To $aList[0]
    _Get_Family($aList[$i])
Next

Func _Get_Family($sDropped)

    Local $sTest, $iCount, $iMax_Count = 0, $iIndex, $aFamily



    ; Start trimming characters from right of the passed string
    For $j = 1 To StringLen($sDropped) - 1
        $sTest = StringTrimRight($sDropped, $j)
        $iCount = 0
        ; Check match for the trimmed string againt every element of the list
        For $k = 1 To $aList[0]
            If StringRegExp($aList[$k], "^" & $sTest & ".*$") Then
                ; Increase count if matched
                $iCount += 1
            EndIf

        Next
        ; If count is higher then cuurent max then store data
        If $iCount > $iMax_Count Then
            $iMax_Count = $iCount

            $iIndex = $j
        EndIf

    Next
    ; We now know the longest string that gives the max number of matches
    
    ; Now extract these matches from the array by matching the trimmed string
    If $iMax_Count Then
        ; Array to hold the matches and the index to fill
        Local $aFamily[$iCount + 1] = [$iMax_Count], $iInsert = 1
        ; Create the trimmed string
        $sBase = StringTrimRight($sDropped, $iIndex)
        ConsoleWrite($sBase & @CRLF)
        ; loop through the array
        For $k = 1 To $aList[0]
            ; If a match
            If StringRegExp($aList[$k], "^" & $sBase & ".*$") Then
                ; Add to the array
                $aFamily[$iInsert] = $aList[$k]
                ; And increase the index
                $iInsert += 1
            EndIf

        Next

        ; And these are the matches for each element
        _ArrayDisplay($aFamily, $aList[$i], Default, 8)

    EndIf



EndFunc

Is that what you wanted? Can a RegEx guru do it better?

M23

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thats very close it seems to find the elements  but it finds both downloads, its only supposed to find the one that i drop on the gui and ignore any others unless i drop them on the gui.

So i give the gui one file from a set and it retrieves all the files from that set  which i then move elsewhere

Many thanks

 

EDIT now ive tried to add to main script with the drop and i cant seem to get it to work, leave it with me and ill see what i can do

Edited by Chimaera
Link to comment
Share on other sites

  • Moderators

Chimaera,

to find files in a download folder that belong together

which is what I thought the function did?  When you pass it a "#######" file it finds all the other files of the "#######" family but none of the "~~~~~~~" ones - and vice versa. If this is not what you want, then please let me know for each of the files in that list which other files it is supposed to match, as we obviously have different ideas of "family".

M23

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

i added your eg to the real list and gave it 1 nero file and it returned both nero family and opencloner family

If i give it nero for eg it should only return nero files

One small question
 

$FindFiles = _FileListToArrayRec($sPath, '*' & StringTrimRight($sFilename, 7) & '*', 1, 0)
    _ArrayDisplay($FindFiles, ".Rar Files")

All i supplied here was a the name of one file which was the drop file using $sFilename

For $i = 1 To $aList[0]
                        _Get_Family($aList[$i])
                    Next

Ive tried modding this but it expects an array which i dont have as i only have a single filename and i dont know the list at this point 
any pointers plz.

Itried like this but im just getting array errors all over the place

$FindFiles = _Get_Family($sFilename)

Link to comment
Share on other sites

  • Moderators

Chimaera,

i added your eg to the real list and gave it 1 nero file and it returned both nero family and opencloner family

Then let me have a copy of the real list.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Chimaera,

I have rewritten the code to make the function self contained so you can use it directly in your script. Does this still return all the files for each elements?

#include <Array.au3>
#include <MsgBoxConstants.au3>

Global $aFileList[] = [25, _
        "####### 12 v12.0.00800 MultiLingual Genial78.par2", _
        "####### 12 v12.0.00800 MultiLingual Genial78.part1.rar", _
        "####### 12 v12.0.00800 MultiLingual Genial78.part2.rar", _
        "####### 12 v12.0.00800 MultiLingual Genial78.part3.rar", _
        "####### 12 v12.0.00800 MultiLingual Genial78.vol00+01.PAR2", _
        "####### 12 v12.0.00800 MultiLingual Genial78.vol01+02.PAR2", _
        "####### 12 v12.0.00800 MultiLingual Genial78.vol03+04.PAR2", _
        "####### 12 v12.0.00800 MultiLingual Genial78.vol07+08.PAR2", _
        "####### 12 v12.0.00800 MultiLingual Genial78.vol15+13.PAR2", _
        "~~~~~~~.v.1.40.208-TE.nfo", _
        "~~~~~~~.v.1.40.208-TE.r00", _
        "~~~~~~~.v.1.40.208-TE.r01", _
        "~~~~~~~.v.1.40.208-TE.r02", _
        "~~~~~~~.v.1.40.208-TE.r03", _
        "~~~~~~~.v.1.40.208-TE.r04", _
        "~~~~~~~.v.1.40.208-TE.r05", _
        "~~~~~~~.v.1.40.208-TE.r06", _
        "~~~~~~~.v.1.40.208-TE.rar", _
        "~~~~~~~.v.1.40.nzb", _
        "~~~~~~~.v.1.40.par2", _
        "~~~~~~~.v.1.40.sfv", _
        "~~~~~~~.v.1.40.vol00+1.PAR2", _
        "~~~~~~~.v.1.40.vol01+2.PAR2", _
        "~~~~~~~.v.1.40.vol03+4.PAR2", _
        "~~~~~~~.v.1.40.vol07+6.PAR2"]

; Loop through the list to test each element individually
For $i = 1 To $aFileList[0]
    MsgBox($MB_SYSTEMMODAL, "Return from:", $aFileList[$i])
    $aFamily = _Get_Family($aFileList[$i], $aFileList)
    _ArrayDisplay($aFamily, "Family", Default, 8)
Next

Func _Get_Family($sDropped, $aList)

    Local $sTest, $iCount, $iMax_Count = 0, $iIndex, $aFamily



    ; Start trimming characters from right of the passed string
    For $j = 1 To StringLen($sDropped) - 1
        $sTest = StringTrimRight($sDropped, $j)
        $iCount = 0
        ; Check match for the trimmed string againt every element of the list
        For $k = 1 To $aList[0]
            If StringRegExp($aList[$k], "^" & $sTest & ".*$") Then
                ; Increase count if matched
                $iCount += 1
            EndIf

        Next
        ; If count is higher then cuurent max then store data
        If $iCount > $iMax_Count Then
            $iMax_Count = $iCount

            $iIndex = $j
        EndIf

    Next
    ; We now know the longest string that gives the max number of matches

    ; Now extract these matches from the array by matching the trimmed string
    If $iMax_Count Then
        ; Array to hold the matches and the index to fill
        Local $aFamily[$iCount + 1] = [$iMax_Count], $iInsert = 1
        ; Create the trimmed string
        $sBase = StringTrimRight($sDropped, $iIndex)
        ; loop through the array
        For $k = 1 To $aList[0]
            ; If a match
            If StringRegExp($aList[$k], "^" & $sBase & ".*$") Then
                ; Add to the array
                $aFamily[$iInsert] = $aList[$k]
                ; And increase the index
                $iInsert += 1
            EndIf

        Next

        Return $aFamily



    EndIf

EndFunc

M23

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hmm im sorry i dont know if im explaining this correct

I drop a single file which gives me this at the check

1
J:\#   Tailored\#  Simple Unpacker\Test Files\## Rar\####### 12 v12.0.00800 Multilingual Genial78.vol01+02.PAR2

I then extract the parts from PathSplit which gives me the $sFilename to use for the search of the rest of the files

$sPath = J:\#   Tailored\#  Simple Unpacker\Test Files\## Rar\
$sDrive = J:
$sDir = \#   Tailored\#  Simple Unpacker\Test Files\## Rar\
$sFilename = ####### 12 v12.0.00800 Multilingual Genial78.vol01+02
$sExtension = .PAR2

I then check the extension against a pre determined list of acceptable file types, the real one is 700 long

$sArchiveExt = '.par2|.par3'
$sArchiveExt &= '|.nfo|.sfv|.nzb|.rar'
Local $aExtTypes = StringSplit($sArchiveExt, "|")

And cycle through the list

Local $FindFiles = 0
For $i = 1 To $aExtTypes[0]

And Then im trying to get a list from the only source i have which is the variable below

$sExtension

From your example

For $i = 1 To $aFileList[0]
    MsgBox($MB_SYSTEMMODAL, "Return from:", $aFileList[$i])
    $aFamily = _Get_Family($aFileList[$i], $aFileList)
    _ArrayDisplay($aFamily, "Family", Default, 8)
Next

Where do i get the data to fill all that when i only have 1 filename?

Sorry for not understanding but this is making no sense to me at all :( as i have no array or anything to use

Im just trying to find all matching files to this filename

####### 12 v12.0.00800 Multilingual Genial78.vol01+02

 

Edited by Melba23
Link to comment
Share on other sites

I know M23 is helping, but look at _IsValidType() in my signature for checking if a filepath matches a "list" of extensions.  Then you have no loops...loops loops looooops!

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Chimaera,

this is making no sense to me at all

I could say the same thing. Let me try and explain what I understand you to want.

You have a single dropped file which you split to get a filename and extension You compare the extension to a very long list of possible extensions and if the extension is "valid" you then want to find all files that are of a similar "family" within a given folder. The function I posted will find all members of a "family" within a folder the contents of which have been placed into an array using _FileListToArray. The parameters of the function are the dropped filename (less the path) and the list of files in the folder.

Here is a short working example of how I see the process:

#include <File.au3>
#include <MsgBoxConstants.au3>

Global $sAutoIt_Path = StringRegExpReplace(@AutoItExe, "(^.*\\)(.*)", "\1")

; Simulate dropped filename
$sDropped = "J:\FilePath\AutoIt3.exe"

; Simulate list of valid extensions
$sArchiveExt = "exe|com|bat"
Local $aExtTypes = StringSplit($sArchiveExt, "|")

; Split dropped filename
Local $sDrive, $sDir, $sFileName, $sExtension

_PathSplit($sDropped, $sDrive, $sDir, $sFileName, $sExtension)
ConsoleWrite($sExtension & @CRLF)

; Check if valid extension (after removing .)
If _ArraySearch($aExtTypes, StringTrimLeft($sExtension, 1)) = -1 Then
    MsgBox($MB_SYSTEMMODAL, "Error", "Not valid extension")
    Exit
EndIf



; Get a list of the files of the correct type in the folder (simulated by the AutoIt root folder)
$aFileList = _FileListToArray($sAutoIt_Path, "*" & $sExtension, $FLTA_FILES)
_ArrayDisplay($aFileList, "All .exe files", Default, 8)

; And now find all the files which could belong to the same family using the function I posted earlier
$aFamily = _Get_Family($sFileName & $sExtension, $aFileList)
; I get everything bar "Unintall.exe" as the rest belong to the "Au*.exe" family
_ArrayDisplay($aFamily, "Family files", Default, 8)

Func _Get_Family($sDropped, $aList)
    Local $sTest, $iCount, $iMax_Count = 0, $iIndex, $aFamily

    For $j = 1 To StringLen($sDropped) - 1
        $sTest = StringTrimRight($sDropped, $j)
        $iCount = 0
        For $k = 1 To $aList[0]
            If StringRegExp($aList[$k], "^" & $sTest & ".*$") Then
                $iCount += 1
            EndIf

        Next
        If $iCount > $iMax_Count Then
            $iMax_Count = $iCount

            $iIndex = $j
        EndIf

    Next
    If $iMax_Count Then
        Local $aFamily[$iCount + 1] = [$iMax_Count], $iInsert = 1
        $sBase = StringTrimRight($sDropped, $iIndex)
        For $k = 1 To $aList[0]
            If StringRegExp($aList[$k], "^" & $sBase & ".*$") Then
                $aFamily[$iInsert] = $aList[$k]
                $iInsert += 1
            EndIf

        Next
        Return $aFamily



    EndIf
EndFunc

Is that anywhere near close to what you are trying to do?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Damn so close i add a spoof file called this
####### 12 v12.0.00800 Multilingual Genial78.part3.x00

As it clearly wont pass the Valid list

and amended my version like this

Local $aFindFiles = 0, $aValidFiles = 0
                    ; Get a list of the files of the correct type in the folder (simulated by the AutoIt root folder)
                    $aFileList = _FileListToArray( $sFolderPath, "*", $FLTA_FILES)
                    _ArrayDisplay($aFileList, "All .exe files", Default, 8)

                    ; And now find all the files which could belong to the same family using the function I posted earlier
                    $aFamily = _Get_Family($sFileName, $aFileList)
                    _ArrayDisplay($aFamily, "Family files", Default, 8)

                    For $i = 1 To $aFamily[0]
                        $sValidCheck = _IsValidFileType( $aFamily[$i], $sArchiveExt)
                        If $sValidCheck  = True Then
;~                          ConsoleWrite($sValidCheck &@CRLF)
                            $aValidFiles =  _ArrayAdd( $aFindFiles, $aFileList[$i])
                        EndIf
                    Next
                    _ArrayDisplay($aValidFiles, "Valid files", Default, 8)

But it keeps failing the last array, where have i gone wrong?

The earlier two array checks work fine all i need to do is exclude the files that are not on the approved list

Edited by Melba23
Link to comment
Share on other sites

  • Moderators

Chimaera,

Does this meet the bill?

#include <File.au3>
#include <MsgBoxConstants.au3>

Global $sAutoIt_Path = StringRegExpReplace(@AutoItExe, "(^.*\\)(.*)", "\1")

; Simulate dropped filename
$sDropped = "J:\FilePath\AutoIt3.exe"

; Simulate list of valid extensions
$sArchiveExt = "exe|com|dat"
Local $aExtTypes = StringSplit($sArchiveExt, "|")

; Split dropped filename
Local $sDrive, $sDir, $sFileName, $sExtension

_PathSplit($sDropped, $sDrive, $sDir, $sFileName, $sExtension)

; Check if valid extension
If _IsValidFileType($sExtension) =  -1 Then
    MsgBox($MB_SYSTEMMODAL, "Error", "Not valid extension")
    Exit
EndIf



; Get a list of the files in the AutoIt root folder
$aFileList = _FileListToArray($sAutoIt_Path, "*", $FLTA_FILES)
_ArrayDisplay($aFileList, "All .exe files", Default, 8)

; Noww find all the files which could belong to the same family using the function I posted earlier
$aFamily = _Get_Family($sFileName, $aFileList)

; And finally check which of these have valid extesions

For $i = UBound($aFamily) - 1 To 1 Step -1
    If _IsValidFileType(StringRegExpReplace($aFamily[$i], "^.*\.", ".$1")) = -1 Then
        _ArrayDelete($aFamily, $i)
        $aFamily[0] -= 1
    EndIf

Next

_ArrayDisplay($aFamily, "Family files", Default, 8)

Func _Get_Family($sDropped, $aList)
    Local $sTest, $iCount, $iMax_Count = 0, $iIndex, $aFamily

    For $j = 1 To StringLen($sDropped) - 1
        $sTest = StringTrimRight($sDropped, $j)
        $iCount = 0
        For $k = 1 To $aList[0]
            If StringRegExp($aList[$k], "^" & $sTest & ".*$") Then
                $iCount += 1
            EndIf

        Next
        If $iCount > $iMax_Count Then
            $iMax_Count = $iCount

            $iIndex = $j
        EndIf

    Next
    If $iMax_Count Then
        Local $aFamily[$iCount + 1] = [$iMax_Count], $iInsert = 1
        $sBase = StringTrimRight($sDropped, $iIndex)
        For $k = 1 To $aList[0]
            If StringRegExp($aList[$k], "^" & $sBase & ".*$") Then
                $aFamily[$iInsert] = $aList[$k]
                $iInsert += 1
            EndIf

        Next
        Return $aFamily



    EndIf

EndFunc



Func _IsValidFileType($sExt)
    Return _ArraySearch($aExtTypes, StringTrimLeft($sExt, 1))
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Done some testing today at work, seems to be fine for the most part

But it fails on this
Capture.thumb.PNG.4ada13d231da44c9905a08

It can find all the files and determine the file_id.diz is not part of the set

But it cant tell any difference between the remaining files

Link to comment
Share on other sites

  • Moderators

Chimaera,

I imagine that is because other than file_id.diz all the other files begin with "t". I suggest changing the loop variable in the _Get_Family function so that it stops when there are still a few letters left in the string - try this:

For $j = 1 To StringLen($sDropped) - 5 ; Rather than 1

Now the function will not shorten the string below that figure when trying to match and so should not match every "t*" file in the array.

It might be worth trying to develop an algorithm which could automatically detect when to stop the shortening. I will have a think about how this might be done - can you let me have a representative sample of the sort of family names you want to detect so I can see what sort of names we are having to distinguish and how we might develop some suitable code.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

thats working again now thx

So does it work by shortening a letter each time till it matches?

The family names could be tons of possibles, ill try and throw one of each type i can find in a folder and show you an image of it, may take a while to collect.

Maybe it need a comparison against the name file as we know the name of the dropped file, maybe its possible to build a test against that filename one letter at a time 

Edited by Chimaera
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...