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.
<object> folder name here </object>
so I can use it later to update an xml file I have
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
.
.BaseName
is - perhaps surprisingly - the same as .Name
- only for files is an extension, if present, removed. Use ForEach-Object
to embed each base name in (the string representation of) an XML element using an expandable (double-quoted) string ( "..."
) :
(Get-ChildItem -Directory c:\test).BaseName |
ForEach-Object { "<object>$_</object>" }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.