How do I do 'dir /s /b' in PowerShell?

Viewed 109568

I have a folder with three files and want the equivalent of dir /s /b in PowerShell. How do I do that?

For example, if the folder name is temp3 and it contains three text files - a.txt. b.txt, and c.txt, doing

C:\temp3> dir /s /b

gives me

C:\temp3\a.txt
C:\temp3\b.txt
C:\temp3\c.txt

How do I get the same result in PowerShell?

8 Answers

This is equivalent:

(dir -r).FullName

If you just want to permanently replace Powershell's dir alias (Get-ChildItem) with a call to cmd dir, for all future powershell windows you're going to open just do the following:

  1. notepad $profile (from powershell window)
  2. when file opens, insert the following rows and save:

    Remove-Item alias:\dir
    function dir($1, $2, $3, $4) {cmd /r dir $1 $2 $3 $4}
    

A variation of Bob answer is to use a pipe for realtime output (having a better feedback in large directories):

dir -r | % FullName

In PowerShell, the command-line to find files is "Get-ChildItem" that have aliases (gci,ls,dir). In the "dir -?", you can find the url explanation : Get-ChildItem

Examples of commands:

dir *.txt -s | select name,length

ls *.txt -s | select fullname

Related