Search code examples
powershellfilesortingdirectorysubdirectory

How to create a printable sorted list of files in a directory and subdirectories without the path with Windows 10 PowerShell


I am looking for a way to create a printable sorted list of files in a directory and subdirectories without the path with Windows 10 PowerShell.

I have tried the following in Command Prompt, but it does not allow me to obtain a sorted list:

D:\books>forfiles /m . /s >d:\books\bookslist.txt

Is there a way to do this in Windows PowerShell?

THANKS


Solution

  • Get-ChildItem is used to list files in powershell. You may have to start go through the basic commands in powershell. Hope this helps!

    Get-ChildItem -Path "C:\temp" *.* -Recurse -File | Select-Object Name | Sort-Object Name | Out-File "C:\temp\fileslist.txt"