equivalent of (dir/b > files.txt) in PowerShell

后端 未结 6 1169
借酒劲吻你
借酒劲吻你 2021-02-05 05:04
dir/b > files.txt

I guess it has to be done in PowerShell to preserve unicode signs.

6条回答
  •  独厮守ぢ
    2021-02-05 05:31

    In PSH dir (which aliases Get-ChildItem) gives you objects (as noted in another answer), so you need to select what properties you want. Either with Select-Object (alias select) to create custom objects with a subset of the original object's properties (or additional properties can be added).

    However in this can doing it at the format stage is probably simplest

    dir | ft Name -HideTableHeaders | Out-File files.txt
    

    (ft is format-table.)

    If you want a different character encoding in files.txt (out-file will use UTF-16 by default) use the -encoding flag, you can also append:

    dir | ft Name -HideTableHeaders | Out-File -append -encoding UTF8 files.txt
    

提交回复
热议问题