Powershell - Trouble With Loops
First I would like to generate a directory listing for all text files in a directory. Next take each of those text files and get-contents. Then I want to go through the contents and search for all text files in another directory which share contents with the first file and output those corresponding matches to a file named after the source file. 

I'm very new at all of this and realize I'm missing some serious fundamental chunks of knowledge. What little scripting experience I have is in Javascript which doesn't seem entirely transferable. (Although programming is programming I'm told.)

This is what I have so far:

    $max = get-content h:test1\one.txt | Measure-Object
    $A = get-content h:test1\one.txt
    For($i=0; $i -lt $max.count ; $i++){
        select-string h:test2\*.txt -pattern $($A[$i]) | Format-Table | Out-File ($i + '.txt')
        }

I'm hoping for something like:


    $max = get-content $files[i] | Measure-Object
        $A = get-content files[i]
        For($j=0; $j -lt $max.count ; $j++){
            select-string h:test2\*.txt -pattern $($A[$j]) | Format-Table | Out-File($files[i].basename + $j + '.txt')
        }

Any and all help would be extremely appreciated, 

Kurtis
Powershell - Trouble With Loops
===

First I would like to generate a directory listing for all text files in a directory. Next take each of those text files and get-contents. Then I want to go through the contents and search for all text files in another directory which share contents with the first file and output those corresponding matches to a file named after the source file. 

I'm very new at all of this and realize I'm missing some serious fundamental chunks of knowledge. What little scripting experience I have is in Javascript which doesn't seem entirely transferable. (Although programming is programming I'm told.)

This is what I have so far:

    $max = get-content h:test1\one.txt | Measure-Object
    $A = get-content h:test1\one.txt
    For($i=0; $i -lt $max.count ; $i++){
        select-string h:test2\*.txt -pattern $($A[$i]) | Format-Table | Out-File ($i + '.txt')
        }

I'm hoping for something like:


    $max = get-content $files[i] | Measure-Object
        $A = get-content files[i]
        For($j=0; $j -lt $max.count ; $j++){
            select-string h:test2\*.txt -pattern $($A[$j]) | Format-Table | Out-File($files[i].basename + $j + '.txt')
        }

Any and all help would be extremely appreciated, 

Kurtis