I found that the following command code provided a robust list of folders and subfolders and created a text document with the list. Command Prompt - Get-ChildItem -Path "Your file Path Name" -Recurse | Sort-Object Name | Out-File -FilePath "list.txt"
Additional Information: The command you used in PowerShell (dir /s /b /o:gn >list.txt) should work fine for listing files and directories recursively. However, PowerShell provides a more robust command for this purpose using the Get-ChildItem cmdlet. I hope this response is a help. Have a better day!