0

I know its easy for you guys but I Need you Your Help. I have 2 CSV files

fileA.csv= All Files Paths on Server in column A

column A
/Volumes/../.../file1.mov
/Volumes/../.../file2.jpg
/Volumes/../.../file3.mp3

Exactly 200K records

FileB.csv= File Names for missing files I need to Located in Column A (File1.mov)

column A
/file2.jpg
/file1.mov
/file4.txt
/file3.mp3

What i need is to Check the file name with extension in fileB.csv and match it with correct path in fileA.csv . If a File name from fileA.csv in FileB.csv is not located it should mention that its not found. so the output file looks like this

ColumnA ColumnB.
File1.mov /Volumes/../.../file1.mov)
File2.jpg /Volumes/../.../file2.jpg)
File3.mp3 N/A

This What i made till now

$org  = import-csv "fileA.csv"
$diff = import-csv "FileBcsv"

foreach($row in $org){

    $diffRow = $diff | Get-Process | Where-Object {$_.rule -eq $row.Rule}
    [pscustomobject]@{
    
       Rule  = $row.rule
       Value = $row.value
       Match = if($row.Value -eq $diffrow.Value){'Match'}else{"NoMatch:" +$row.Value+ $diffrow.Value}
    
    }   
}
$Results | Export-Csv -Path "./OutPutFile.csv" -NoTypeInformation

Its still processing so i still dont know the if its gonna work or not

iRon
  • 20,463
  • 10
  • 53
  • 79
  • 1
    You should share an example of fileA.csv and an example of fileB.csv (as plain text) and how the expected outcome would look like in order to properly understand what you're looking to accomplish. You mention that you need to check file names in fileB.csv however your code is showing the use of `Get-Process`, which doesn't make any sense. – Santiago Squarzon Aug 21 '22 at 15:59
  • Well I tried Multiple commands but none gave the correct output – Rami Eyada Aug 21 '22 at 16:00
  • Using this [`Join-Object script`](https://www.powershellgallery.com/packages/Join)/[`Join-Object Module`](https://www.powershellgallery.com/packages/JoinModule) (see also: [In Powershell, what's the best way to join two tables into one?](https://stackoverflow.com/a/45483110/1701026)): `Import-Csv .\fileA.csv |FullJoin (Import-Csv .\fileB.csv) -on { Split-Path -Leaf $_.'Column A' } -Name A_,B_` – iRon Aug 21 '22 at 17:04
  • @SantiagoSquarzon yes its totally plain text. As for the expected outcome i wrote it in the question. above its the table – Rami Eyada Aug 21 '22 at 17:45
  • @iRon tried you Modification but i think i will have to make an if condition in the middle because it gave me this error ForEach-Object: Cannot bind argument to parameter 'Path' because it is null. – Rami Eyada Aug 22 '22 at 01:22
  • That means that your colums aren't called `Column A` as defined in your question. Please be exact in your [mcve] definition. – iRon Aug 22 '22 at 06:28
  • Are `fileA.csv` and `fileB.csv` actually [`csv` files](https://en.wikipedia.org/wiki/Comma-separated_values)? Or just (headless) lists of filenames in which case you shouldn't use [Import-Csv](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/import-csv) at all but [Get-Content](https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-content): `Get-Content .\fileA.csv |FullJoin (Get-Content .\fileB.csv) -on { Split-Path -Leaf $_.Value } -Name A,B` – iRon Aug 22 '22 at 11:36
  • How would you like to handle multiple matches? Should the output only contain the first path found? – An-dir Dec 19 '22 at 20:07

0 Answers0