Link to home
Start Free TrialLog in
Avatar of daveTechSearch
daveTechSearchFlag for Canada

asked on

Powershell: Match array strings (from 2 txt files) line for line

I am trying to figure out how to join strings from two arrays (line for line).
Overview:
I need to run a third party app against a set of files. The output file generated by the 3rd party app (different file format) needs to be delivered to the same directory as the source file.
EXAMPLE:
I have generated the required files:
$sourceFiles = c:\temp\sFiles.txt
$sourceDirs = c:\temp\sDirs.txt
# each line in both arrays need to be matched one for one
For instance:
sourceFiles.txt would contain:
c:\one\please.log
c:\one\two\help.log
c:\one\two\help2.log
c:\one\three\me.log
sourceFolders.txt would contain:
c:\one
c:\one\two
c:\one\two
c:\one\three
As stated, I need to match the two line for line (up to 10000 lines)...SO

I need to be able to loop through the arrays run the app something like this:
& 'c:\program files\3rdPartyApp\App.exe' $sourceFile $sourceDir
OR
& 'c:\program files\3rdPartyApp\App.exe' c:\one\please.log c:\one\two
.... and so on.

Not sure if this is possible?
Avatar of rlandquist
rlandquist
Flag of United States of America image

Try this.
$sourceFiles  = Get-Content "c:\temp\sFiles.txt"
$sourceDirs = Get-Content "c:\temp\sDirs.txt"

for ($i = 0; $i -lt $sourceFiles .count; $i++)
{
	[Diagnostics.Process]::Start('c:\program files\3rdPartyApp\App.exe', $sourceFiles [$i] $sourceDirs[$i])
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rlandquist
rlandquist
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of daveTechSearch

ASKER

should that increment to the next line?... I am seeing it only increment to the next character on the first line
'c', ':', and '\'
 
Got it to work, with a little bit of rework... Thanks for your help!