Quantcast
Channel: Merging counting unique paths in powershell - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Merging counting unique paths in powershell

$
0
0

I am trying to figure out a way to merge all the parents directory paths into on e path, so imagine I have this data in a txt file:

\BANANA\APPLE\BERRIES\GRAPES\
\BANANA\APPLE\BERRIES\
\BANANA\APPLE\BERRIES\GRAPES\PEACH\
\BANANA\APPLE\
\BANANA\
\BANANA\APPLE\BERRIES\GRAPES\PEACH\AVOCADO\

I want the output of my loop to be just:

\BANANA\APPLE\BERRIES\GRAPES\PEACH\AVOCADO\

Because it is the longest path containing all the other previous paths. But I am trying to do a loop for all the unique paths in a file containing all the previous parent folders as follows:

rm UNIQUE_PATHS.txt
    #"LINE:"+$line 
    $count=0
foreach ($line in gc COUNT_DIR.txt){ 

    foreach ($line2 in gc COUNT_DIR.txt){ 
        #  $line -contains $checking

        if ($line2.contains($line2)) {
        "COMPARING:"+$line2+" AND "+$line
        $count = $count+1 
        }

    if ($count -eq 1){

    $line+$count >> UNIQUE_PATHS.txt

    }

      }
 }
 cat UNIQUE_PATHS.txt

So looks my count of the unique path is not working, that should be a better script for this ?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images