Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Comparing string in text file to folder path

$
0
0

I have a text file which has directory locations, one directory location per line.

What I am trying to do is, loop a set of directories and check if their FullName exists in the said text file.

I tried couple of approaches but I don't seem to be getting the expected result. The below string compare doesn't seem to work, can someone have a look and please let me know if I am going wrong somewhere?

This is what the code looks like:

$TextToWrite="<table border='1'><tr><th align='left'>Directory</th><th align='left'>Deletion Rule</th>"

$rowsInDeleteTextFile= Get-Content "\\somedir\filesNames.txt"

$path='\\root\subdir'

$downloadFolders=Get-ChildItem $path | where-object {$_.PSIsContainer -eq $True}


foreach($folder in $downloadFolders)

{

    if($rowsInDeleteTextFile -contains $folder.FullName)

    {

        Write-Output $folder.FullName + " :  ----> True"

        $TextToWrite+="<tr><td>" + $folder.FullName + "</td><td>True</td></tr>"

    }

    else

    {

        Write-Output $folder.FullName + " :  ----> False"

        $TextToWrite+="<tr><td>" + $folder.FullName + "</td><td>False</td></tr>"

    }

}

$TextToWrite+="</table>"

$TextToWrite | out-file "D:\Powershellexamples\test.htm"

 

This is what the filesNames.txt looks like:

\\root\subdir\dirnameA,5,*

\\root\subdir\dirnameB,5,*

\\root\subdir\dirnameC,5,*

\\root\subdir\dirnameD,5,*

\\root\subdir\dirnameE,5,*

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles