[英]export folders list in specific pattern PowerShell
I need to export a list of folders in a specific pattern my code is我需要以我的代码的特定模式导出文件夹列表
$list = Get-ChildItem -Path c:\test\ -Directory | Select-Object BaseName
I need the final output to be.我需要最终的 output 。
<object> folder name here </object>
so I can use it later to update an xml file I have所以我以后可以用它来更新我拥有的 xml 文件
how can i do it?我该怎么做?
$list = Get-ChildItem -Path d:\tmp\ -Directory | Select-Object @{name="baseNameInTag"; expression = {"<object>{0}</object>" -f $_.BaseName}}
Use member-access enumeration to get all .BaseName
values from the output objects emitted by Get-ChildItem
.使用成员访问枚举从Get-ChildItem
发出的 output 对象中获取所有.BaseName
值。
.BaseName
is - perhaps surprisingly - the same as .Name
- only for files is an extension, if present, removed.顺便说一句:对于目录, .BaseName
- 也许令人惊讶 - 与.Name
相同 - 仅对于文件是扩展名,如果存在,则删除。 Use ForEach-Object
to embed each base name in (the string representation of) an XML element using an expandable (double-quoted) string ( "..."
) :使用ForEach-Object
使用可扩展(双引号)字符串( "..."
)将每个基本名称嵌入到 XML 元素(的字符串表示形式)中:
(Get-ChildItem -Directory c:\test).BaseName |
ForEach-Object { "<object>$_</object>" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.