title: From files with same name but different extension(*.pdf and *.rtf), if *.rtf is newer, output message on console
body: <p>I have folders and subfolders with files with two different extensions. I need to check the lastwrite time of both corresponding files.<br>
  For example  </p>
  
  <pre><code>file1.rtf
  file1.pdf
  file2.rtf
  file2.pdf
  file3.rtf
  file3.pdf
  </code></pre>
  
  <p>... and so on </p>
  
  <p>I need to make sure that RTF files ran before PDF files. If the PDF is older than RTF, that means it's an error. I need to output those file names on powershell console with a message indicating this error. Any help would be appreciated. I tried to find and run different codes I found online, but nothing worked. Thank you. the code the code </p>
  
  <pre><code>$path = Read-Host "Enter Path"
  $files = Get-ChildItem -Path $path -Filter "*.txt"            
  
  $files | %{ 
      $rtf=$($_.BaseName+".rtf")
      If (Test-Path $rtf){
      If ($_.LastWritetime -lt (Get-Item $rtf).LastWriteTime){
  
      $file = $_.OpenText();            
      $lineNum = 1;            
      Write-Host "Checking file"$_.Name -f Yellow  "$_ is older than $rtf file"   ;            
      while($file.EndOfStream -ne $true)            
      {   
          $line = $file.ReadLine();                    
          if($line -ne $null)            
          {  
              if($line.ToLower().Contains("error") -or $line.ToLower().Contains("exception"))            
              {  
                  Write-Host "Line: $lineNum " -NoNewline -ForegroundColor Green;            
                  Write-Host $line -f Red;            
              }            
          }             
  
          $lineNum++;                   
      }            
  }            
  }
  } 
  </code></pre>