I'm trying to find out a way use a loop to go through directories with different names, go into a folder in each of those with the same name (TSO), grab the text file, use it for functions (Extractor and VisioMaker), then repeat the process for the next folders. To clarify, I'm only having a problem with the loop portion. Here's the directory format:
Main Folder (TestCircuits) >
- Folder1 > TSO > Name1.txt
- Folder2 > TSO > Name2.txt
- Folder3 > TSO > Name3.txt
- ...
Set-Location " \TestCircuits"
#Testing
$location = " \TestCircuits"
Foreach-Object {
#select only the latest text file
$Global:fileM = Get-ChildItem "*\TSO\*.txt" | sort LastWriteTime | select -last 1 | Get-Item
#set new variable for clarity in later function
$Global:ccsd = $fileM
#use recurse for the loop? Seems to work fine
$Global:files = Get-ChildItem " \TestCircuits" -Recurse
#path format for the loop might be janky, but seems to work
$Global:textFileData = Get-ChildItem " \TestCircuits\*\TSO\$ccsd" | Get-Content
$Global:textFileDataRaw = Get-ChildItem " \TestCircuits\*\TSO\$ccsd" | Get-Content -raw
foreach ($fileM in $files) {
#need to use $fileM but not sure how
Function Extractor {
#code that sets variables from text in each file
#uses $ccsd variable to get text
}
Function VisioMaker {
#code that makes Visio doc from variables each time
#variables used are from Extractor function
}
}
}
Any help would be appreciated. Thanks!