System.Object [] - 文件名相同时

时间:2017-08-24 07:41:06

标签: powershell csv

我在E:\ MyFiles \和E:\ MyFiles \ August中有文件。我使用PowerShell将文件路径存储在csv文件中(E:\ CSVPaths.csv)。

这是我的剧本:

$exclude = @(".html", ".tt", ".xaml", ".csproj", ".sln", ".xml", ".cmd", ".txt",".svn")
"DirectoryPath, SourceFileName" | Out-File -FilePath "E:\CSVPaths.csv" -Encoding ASCII 
$table = (get-childitem -recurse "E:\MyFiles" -File -ErrorAction SilentlyContinue | Where-Object { $exclude -notcontains $_.Extension }).Fullname 
foreach ($row in $table)
{
  $file=Get-ChildItem -recurse $row
  $fileObject = new-object PSObject
  $fileObject | add-member -membertype NoteProperty -name "DirectoryPath" -Value  $file.DirectoryName 
  $fileObject | add-member -membertype NoteProperty -name "SourceFileName" -Value  $file.Name 
  $newrow=$fileObject
  Export-Csv "E:\CSVPaths.csv" -inputobject $newrow -append -Force
}  

在E:\ MyFiles和E:\ MyFiles \ August文件夹中,都有相同名称的文件(例如:Audit_Report.csv)。导出到csv时,它们在System.Object[]DirectoryPath中存储为SourceFileName,如下所示:

DirectoryPath      SourceFileName

System.Object[]     System.Object[] 
E:\MyFiles\August   Audit_Report.csv

请帮助解决此问题。

1 个答案:

答案 0 :(得分:1)

没有必要使用循环来获得AFAICS之后的输出。

SELECT 
    con.email,
    acct.Id,
    acct.BillingCity,
    acct.BillingCountry,
    acct.BillingPostalCode,
    acct.BillingState,
    acct.BillingStreet,
    acct.Name,
    acct.Phone 
FROM account acct
     LEFT OUTER JOIN 
     contact con ON con.account_id = acct.account_id
WHERE acct.LastModifiedDate < #[flowVars['timestamp']]