As far as I can test this code does what you want it to do.
I have modified the script so that all arrays hold the number of rows in the first row.
I have modified the PCRE so the search pattern has to be found at column 1 of each record
I have added some debugging code. Can easily be removed
#include <Array.au3>
#include <File.au3>
; Documentation:
; All arrays store the row/column count in row 0
Global $aArrayInput, $aArrayOutput, $aMat
Global $sDir = @ScriptDir
Global $sFileName = '*'
Global $sFileExtension = 'texture.dds' ; or '*' for all files or 'pdf' for just PDFs
Global $sListPath = @ScriptDir & '\TextureList.lst'
Global $sFind = 'textures\cperrella\fabric\cloth_knits\wrinkles_01_n.texture' & '.dds'
Global $sMatInput = @ScriptDir & '\civ_female_act3.model_materials.txt'
$aArrayOutput = _FileListToArrayRec($sDir, $sFileName & '.' & $sFileExtension, 1, 1, 0, 2)
; if @error then Exit ConsoleWrite("_FileListToArrayRec: @error=" & @error & ", IsArray($aArrayOutput): " & IsArray($aArrayOutput) & @CRLF)
If IsArray($aArrayOutput) Then
If Not FileExists($sListPath) Then _FileWriteFromArray($sListPath, $aArrayOutput, 1) ; Do not write the record count to the file
_FileSearchInTXT()
Else
Global $aArrayOutput[1] = [0] ; Modified: $aArrayOutput needs to be defined as an array as _FileListToArray might not return/create the array
EndIf
_FileReadToArray($sMatInput, $aMat, $FRTA_COUNT)
_ArrayDisplay($aMat, "before Moving rows") ; ==> Just for debugging can be removed
; Lines with certain strings should be excluded
Global $sExclude = "(?i)^===*|(?i)^---*|(?i)^shader*|(?i)^material*|(?i)^template*|^\s|^ *"
$sExclude = StringReplace($sExclude, ".", "\.")
; $sExclude = StringReplace($sExclude, "?", ".") ; REMOVED as it would kill (?i) in the pattern
$sExclude = StringReplace($sExclude, "*", ".*?")
; Remove all lines holding on of the $sExclude patterns or empty lines
Global $iOutIndex = 1
For $iInIndex = 1 To $aMat[0]
If Not StringRegExp($aMat[$iInIndex], $sExclude) And $aMat[$iInIndex] <> "" Then
ConsoleWrite("Moved : " & $iInIndex & " | " & $iOutIndex & " | " & $aMat[$iInIndex] & @CRLF) ; ==> Just for debugging can be removed
$aMat[$iOutIndex] = $aMat[$iInIndex]
$iOutIndex += 1
Else
ConsoleWrite("Ignored: " & $iInIndex & " | " & $iOutIndex & " | " & $aMat[$iInIndex] & @CRLF) ; ==> Just for debugging can be removed
EndIf
Next
_ArrayDisplay($aMat, "After moving rows") ; ==> Just for debugging can be removed
ReDim $aMat[$iOutIndex]
$aMat[0] = $iOutIndex - 1
_ArrayDisplay($aMat, "After ReDim") ; ==> Just for debugging can be removed
For $i = 1 To $aMat[0]
For $j = 1 To $aArrayOutput[0]
If $aMat[$i] = $aArrayOutput[$j] Then
ConsoleWrite("Copying file " & $aArrayOutput[$j] & " to " & @ScriptDir & @CRLF) ; ==> Just for debugging can be removed
FileCopy($aArrayOutput[$j], @ScriptDir, $FC_NOOVERWRITE)
Else
ConsoleWrite("No match found for " & $aMat[$i] & @CRLF)
EndIf
Next
Next
_ArrayTrim($aMat, 17, 0, 1)
_ArrayDisplay($aMat, "Array (trimmed)", Default, 8)
Exit
;~ ----------------------------------------------------------------------------------------------
Func _FileSearchInTXT()
If $sListPath <> '' And $sFind <> '' Then
_FileReadToArray($sListPath, $aArrayInput, $FRTA_COUNT)
For $i = 1 To $aArrayInput[0]
If StringInStr($aArrayInput[$i], $sFind) Then
ConsoleWrite("Found file: " & $aArrayInput[$i] & @CRLF)
EndIf
Next
Else
MsgBox(48, 'Error', 'A file was not picked or what to find was cancelled/empty!')
EndIf
EndFunc ;==>_FileSearchInTXT