PS C:\Users\user> Get-ChildItem | Format-Wide -AutoSize
Directory: C:\Users\user
Contacts Cookies
Desktop Documents
Downloads Favorites
PS C:\Users\user>
是否有一种方便的方法可以省略目录头以及输出中的 7 个空行?
如果解决方案与以下方面配合良好,则可获得加分目录颜色。
答案1
对于一个非常简单的例子,我会选择名称:
PS> (Get-ChildItem).Name
.docker
.ssh
.vscode
3D Objects
Calibre Library
Code
Contacts
Documents
Downloads
EneticsNC
Favorites
答案2
这允许使用Format-WIde
并删除前导和尾随的空白行:
(Get-ChildItem | Select name | Format-Wide | Out-String).Trim("$([char]0x0a+[char]0x0d)")
输出:
PS C:\...\keith>(gci | select name | format-wide | out-string).Trim("$([char]0x0a+[char]0x0d)")
Contacts Desktop
Documents Downloads
Favorites Links
Music OneDrive
Original 3D Content Pictures
Sandbox Saved Games
Screenshots Searches
Standalone Programs Videos
2002271222HotKeys.reg 2002271230HotKeys.reg
5f7b5f1e01b83767.automaticDestinations-ms A20200807.txt
adstest.txt AllFolders-StandardDetails.reg
arrByte.xml atesty.reg
audioprops.txt B20200807.txt
BadTableWithDups bytes2.txt
Documents2002271232HotKeys.reg DTShortcut.ps1
dummy.ini env.txt
File Explorer.lnk filelist.txt
file_ex1_ex2.ex3 gci.txt
help.txt hex.bin
hkcrlevel1.txt hkcrlevel2.txt
HKLMAllFoldersDetails.txt hotkeys.xml
junctions.txt list.txt
listtxt mkdir.txt
names.txt NoEmpties.xml
out.txt out2.txt
out3.txt outnum.txt
PicLibTVBytes.txt Profcopy.ps1
redirect.txt RegCommandExamples.txt
reginihelp.txt Relative.lnk
sc.lnk script.ps1
set-clipboard Settings.reg
sha256.txt sha2562.txt
star.txt test (2).txt
test.txt transTest.txt
usf.txt WithEmpties.xml
PS C:\...\keith>