0

I have two text file and in this txt files there is an MD5 checksums of some backup files. I am trying to compare these text files and if MD5 is same I am try to adding near "-2" if it is different adding "-1" but the problem is directories are different that is why when I compare results being always -1. How can I choose exactly MD5 place in the file? I think if I can change the [System.IO.File]::ReadAllText('C:\Users\trerulug\Documents\Inventory1\Inventory.txt') in the code it could work.

Output :

MD5       C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory\12348318433batch.xml
MD5       C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory2\12348318433batch.xml,-1
MD5       86CA06D361850A9385CA475E133E4182 C:\Users\william\Documents\Inventory\12348318433batch.xml.xml
MD5       86CA06D361850A9385CA475E133E4182 C:\Users\william\Documents\Inventory2\12348318433batch.xml.xml,-1
MD5       A75515C272B4716FB160DDA644BC9955 C:\Users\william\Documents\Inventory\12348318433batch.xml
MD5       A75515C272B4716FB160DDA644BC9955 C:\Users\william\Documents\Inventory2\12348318433batch.xml,-1
& {
    $ErrorActionPreference = 'Stop'
    $OFS = ','

    try {
        $To = [System.IO.File]::ReadAllText('C:\Users\Williams\Documents\Inventory1\Inventory.txt')
        $From = & {
            if (-not $To.EndsWith([System.Environment]::NewLine)) { '' }
            Get-Content -Path C:\Users\william\Documents\Inventory2\Inventory.txt |
                ForEach-Object { "$($_, @(-1, -2)[[int]$To.Contains($_)])" }
        }

        Add-Content -Path C:\Users\william\Documents\Inventory1\Inventory.txt -Value $From
        Get-Content -Path C:\Users\trerulug\Documents\Inventory1\Inventory.txt
    } catch {
        $_ | Out-String | Write-Warning
    }
}

Expected output:

MD5       C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory\12348318433batch.xml
MD5       86CA06D361850A9385CA475E133E4182 C:\Users\william\Documents\Inventory2\12348318433batch.xml.xml
MD5       A75515C272B4716FB160DDA644BC9955 C:\Users\william\Documents\Inventory2\12348318433batch.xml
MD5       C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory2\12348318433batch.xml,-2
MD5       86CA06D361850A9385CA475E133E4182 C:\Users\william\Documents\Inventory2\12348318433batch.xml.xml,-2
MD5       A75515C272B4716FB160DDA644BC9955 C:\Users\william\Documents\Inventory2\12348318433batch.xml,-2
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Please add what exactly is the content of both files as in current format it's unclear what is where and what is the output. Regarding your problem, you can just replace base path (`C:\Users\william\Documents\Inventory`->`C:\Users\william\Documents\Inventory2`) while comparing and they will be the same. – Robert Dyjas Jul 17 '19 at 19:51
  • Contents are exactly like that in the txt files. For example : MD5 C1FA0C20EEFD90076AEFAAB199D854B9 C:\Users\william\Documents\Inventory\12348318433batch.xml. I can not give same directory because txt files are in different directories. For testing I gave same numbers in txt files I can compare but in this situation directories different that is why even hashes are same ( like : C1FA0C20EEFD90076AEFAAB199D854B9) it is thinking that different and giving -1 because of the different directories in my opinion. Is there any way to clerify exactly hash place? – William Kendly Jul 17 '19 at 20:03

0 Answers0