title: powershell script can't find a file that exists
body: <p>I have this script that creates files using bcp. As BCP doesn't export data with header i need to join both files into. If i run the code in another script it creates the csv file but if i run this script it fails saying files DOES NOT EXIST, that is the last section of the script below (#THE PROBLEM STARTS HERE).
  Appreciate any help.</p>
  
  <pre><code>Set-StrictMode -Version Latest
  $ErrorActionPreference = "Stop"
  $PSDefaultParameterValues['*:ErrorAction']='Stop'
  
  $bcp = 'c:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe'
  $delimiter = '","'
  $server = 'BLABLABLA'
  $database = 'DMB'
  $schema = '.dbo.'
  $dbschema = $database + $schema
  $atresult = "@result"
  $commas = " + ',','') + "
  $head1 = 'Use '
  $head2 = ' Declare ' # atresult
  $head3 = ' varchar(max) select ' # atresult
  $head4 = ' = COALESCE(' #atresult $commas
  $head5 = 'COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ' # tablename
  $head6 = ' select ' #atresult
  $tables = @('EntityTypes_20181205','FieldFieldTypeInfo')
  $output_path = 'D:\Temp\DataModelBuild\'
  # Deletes any file in Destination Folder
  #if ( (Get-ChildItem $output_path | Measure-Object).Count -ne 0) {}
  Get-ChildItem -Path $output_path -Include *.* -File -Recurse | foreach { $_.Delete()}    
  
  
  foreach ($element in $tables) 
      {
          # GET COLUMN NAMES into header file
          $outputFile = $output_path + $element + ".header"
          $NQ = '"' + $head1 + $database + $head2 + $atresult + $head3 + $atresult + $head4 + $atresult + $commas + $head5 + ''' + $element + ''' + $head6 + $atresult + '"'
          #$arglist = "(" + $NQ + " queryout " + $outputFile + ", -S " + $server + " -T -t" + $delimiter + " -c -k)"
          $arglist  = @('"',
                        $head1,
                        $database,
                        $head2,
                        $atresult,
                        $head3,
                        $atresult,
                        $head4,
                        $atresult,
                        $commas,
                        $head5,
                        "'$element'",
                        $head6,
                        $atresult,
                        '"',
                        " queryout $outputFile",
                        "-S $server -T -t$delimiter -c -k")
          #write-output $arglist
          Start-Process -FilePath $bcp -ArgumentList $arglist
          #Read-Host
  
          # GET DATA into data file
          $outElement = $dbschema + "[" + $element + "]"
          $outputFile = $output_path + $element + ".data"
          $arglist  = @($outElement, "out $outputFile", "-S $server -T -t$delimiter -c -k")
          Start-Process -FilePath $bcp -ArgumentList $arglist
          #write-output $arglist
          #Read-Host
          # Merge header and data to csv
          #Invoke-Expression "&amp;'$ExtPs1' -FilePath $output_path -FileName $element"
          #Write-Output "call "
          #Invoke-Expression "&amp;'D:\idna\PedroTemp\cp2csv.ps1' $output_path $element"
          #Read-Host
  
          #THE PROBLEM STARTS HERE       
          $File1 = @("$output_path$element.header")
          $File2 = @("$output_path$element.data")
          $File3 = @("$output_path$element.csv")
          write-output $File1, $File2, $File3
          If (-not (Test-Path -Path $File1)) {
                      Write-Error "File DOES NOT EXIST '$File1'" -ErrorAction Stop
                      } else {
                      Write-Host "File EXIST"
                      }
          Add-Content $File3 -value (Get-Content $File1)
          Add-Content $File3 -value (Get-Content $File2)
          #write-output $File1, $File2, $File3 -ErrorAction Stop
          Read-Host
  }
  </code></pre>
  
  <p>My question is why isn't the script detecting the file?
  Is there any problem with the string?</p>