Search code examples
powershelldir

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


dir/b > files.txt

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


Solution

  • Get-ChildItem | Select-Object -ExpandProperty Name > files.txt
    

    or shorter:

    ls | % Name > files.txt
    

    However, you can easily do the same in cmd:

    cmd /u /c "dir /b > files.txt"
    

    The /u switch tells cmd to write things redirected into files as Unicode.