我在寫一個應該清理我的Visual Studio項目的小PowerShell腳本。我的策略是在子目錄中找到所有項目文件(例如* .csproj)。項目文件的父文件夾應該是項目目錄。從那裏很容易到達bin和obj子文件夾。PowerShell:選擇對象後的意外序列類型
用下面的代碼片段,我想找到的所有項目文件夾:
$dirs = Get-ChildItem -Recurse -File -Path $start_dir -Include *.csproj | select Directory
我希望這個語句的求System.IO.DirectoryInfo對象序列。令我驚訝的是,情況並非如此。事實上,你得到一個Selected.System.IO.FileInfo序列:
PS> Get-ChildItem -Recurse -File -Path $start_dir -Include *.csproj | select Directory | gm
TypeName: Selected.System.IO.FileInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Directory NoteProperty System.IO.DirectoryInfo Directory=C:\dev\proj\ART\Sources\ART.Adapter
有人可以解釋這種行爲嗎?有人知道另一個評估爲一系列DirectoryInfo對象的語句嗎?