Jump to content

_ArraySearch not working or am i using it wrong?


Recommended Posts

Im trying to seperate 2 different file endings from an array but it doesnt seem to work

From the reading ive being doing this should be a selective string search i think but it never activates

This is the array of files in a folder im working with

 

$aArchiveFile = _FileListToArrayRec(@ScriptDir, "*.7z*;*.001;*.zip;*.rar;*.r00", 1, 0) 

Row|Col 0

[0]|4
[1]|Ashampoo.Snap.7.v7.0.8-TE.part1.rar
[2]|Ashampoo.Snap.7.v7.0.8-TE.part2.rar
[3]|Ashampoo.Snap.7.v7.0.8-TE.part3.rar
[4]|Ashampoo.Snap.7.v7.0.8-TE.part4.rar
 

 Im just trying to split them down one path or the other

If $aRarFile = _ArraySearch($aArchiveFile,'.rar',0,0,0,1) Then
            ConsoleWrite($aRarFile & " .Rar Files " & @CRLF)

    ElseIf $aRarFile = _ArraySearch($aArchiveFile,'.zip',0,0,0,1) Then
            ConsoleWrite($aRarFile & " .7z Files " & @CRLF)
    EndIf

Ideally id like it to do this

If $aRarFile = _ArraySearch($aArchiveFile,'*.rar|*.r00|*.001',0,0,0,1) Then
or more likely will be
If $aRarFile = _ArraySearch($aArchiveFile,'*.rar',0,0,0,1) Or _ArraySearch($aArchiveFile,'*.001',0,0,0,1) Or _ArraySearch($aArchiveFile,'*.r00',0,0,0,1) Then

But i cam do seperate ElseIf to cover that

Anyway can you tell me why its not working please

Many Thanks

Link to comment
Share on other sites

_ArraySearch return only the position, it doesn't filter the array:


Try this:

#include <Array.au3>

Global $aArchiveFile[6] = [5, "Ashampoo.Snap.7.v7.0.8-TE.part1.rar", "Ashampoo.Snap.7.v7.0.8-TE.part2.rar", "Ashampoo.Snap.7.v7.0.8-TE.part3.rar", "Ashampoo.Snap.7.v7.0.8-TE.part4.rar", "More.Warez.zip"]
Global $aRarFile

$aRarFileZ = WFileZLister($aArchiveFile)
_ArrayDisplay($aRarFileZ)

$aRarFileZ = WFileZLister($aArchiveFile, "zip")
_ArrayDisplay($aRarFileZ)


Func WFileZLister($aArchiveFile, $sSuffix = "rar", $b1Based = 1)
    Local $aWFilez[UBound($aArchiveFile)], $i, $j = 0
    For $i = $b1Based To UBound($aArchiveFile) - 1
        If StringRegExp($aArchiveFile[$i], ".*\.(" & $sSuffix & ")", 0) Then
            $aWFilez[$j] = $aArchiveFile[$i]
            $j += 1
        EndIf
    Next
    ReDim $aWFilez[$j]
    Return $aWFilez
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

_ArraySearch return only the position, it doesn't filter the array:

Try this:

#include <Array.au3>

Global $aArchiveFile[6] = [5, "Ashampoo.Snap.7.v7.0.8-TE.part1.rar", "Ashampoo.Snap.7.v7.0.8-TE.part2.rar", "Ashampoo.Snap.7.v7.0.8-TE.part3.rar", "Ashampoo.Snap.7.v7.0.8-TE.part4.rar", "More.Warez.zip"]
Global $aRarFile

$aRarFileZ = WFileZLister($aArchiveFile)
_ArrayDisplay($aRarFileZ)

$aRarFileZ = WFileZLister($aArchiveFile, "zip")
_ArrayDisplay($aRarFileZ)


Func WFileZLister($aArchiveFile, $sSuffix = "rar", $b1Based = 1)
    Local $aWFilez[UBound($aArchiveFile)], $i, $j = 0
    For $i = $b1Based To UBound($aArchiveFile) - 1
        If StringRegExp($aArchiveFile[$i], ".*\.(" & $sSuffix & ")", 0) Then
            $aWFilez[$j] = $aArchiveFile[$i]
            $j += 1
        EndIf
    Next
    ReDim $aWFilez[$j]
    Return $aWFilez
EndFunc

Br,

UEZ

Thanks for that, im currently trying to make it work based on what ever the folder contains so if there is rar it starts one path or zip it starts another path

_ArrayFindAll ?

I did play with this as well, but i couldnt make it work like i wanted

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...