1
我在E:\ MyFiles \和E:\ MyFiles \ August中有文件。我正在使用PowerShell將文件路徑存儲在csv文件(E:\ CSVPaths.csv)中。System.Object [] - 當文件名相同時
這是我的腳本:
$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 \文件夾月,有同名文件(例如:Audit_Report.csv)。雖然出口到它們被存儲爲System.Object[]
在DirectoryPath
和SourceFileName
CSV(如下所示):
DirectoryPath SourceFileName
System.Object[] System.Object[]
E:\MyFiles\August Audit_Report.csv
請幫助解決這個問題。
_shell script_?你的意思是PowreShell? – Clijsters
@Clijsters:Powershell – user3189916