I am working on following script which tries to read a text file, and then run an algorithm with the collected data. The algorithm must be applied to each file in the current folder, so there are 2 main loops.
Loop 1 is for files in folder.
Loop 2 is for the text line entries used in the algorithm.
Loop 3 is for the algorithm itself.
#$path = (Get-Item -Path ".\" -Verbose).FullName
$path = split-path -parent $MyInvocation.MyCommand.Definition
$files = Get-ChildItem "$path\test" -r # root path $PSScriptRoot
#echo $path
#echo $files
#echo $files.Count
ForEach ($file in $files){
echo "the value of i is" $i
#echo $file.FullName
#iterate through files from the current folder.
$data = Get-Content -Path $files.FullName
#echo "$data"
# parse DisabledFeatures.txt file as array of strings (1 string per line of the file)
$feature = Get-Content "$path\Disabled_Features.txt"
#echo $feature.Count
#iterate for each string entry in $feature array (read from txt file)
for($counter=0; $counter -lt $feature.Count; $counter++){
#retrieve array value to use it in the main algorythm
$groupID = $feature[$counter]
echo $groupID
$data | ForEach-Object -Begin { $ignore = $false; $levels = 0 } -Process {
#Start ignoring text after we've found the trigger
if($_ -match "^#ifdef $groupID") {
$ignore = $true
ECHO "TRUE ifdef feature"
}
#Track nested groups
elseif($ignore) {
if ($_ -match '^#ifdef') {
$levels++
echo "levels++"
}
elseif ($_ -match '#endif') {
if($levels -ge 1) { $levels-- }
#If no nesting, we've hit the end of our targeted group. Stop ignoring
else { $ignore = $false }
echo "stop ignoring"
}
}
#Write line
else { $_ }
echo "write line"
}
}
}
Edit: Updated script.
$i -ltand$counter -lt