1

When I type dir /A into terminal I get desirable output, but when I type the same to Powershell i get

dir : Cannot find path 'C:\A' because it does not exist.
+ CategoryInfo          : ObjectNotFound: (C:\A:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

etc. Doesn't matter if I type dir /A . or dir . /A I thought that the Powershell is an extension of terminal so everything that works on terminal will be expanded on ps. How can I found the reason behind this behaviour?

4
  • The message says C:\A. Did you enter /A or \A?
    – Toto
    Commented 21 hours ago
  • @Toto that question is irrelevant. Powershell's dir is an alias for get-childitem, and get-childitem does not have a /a parameter. See my answer.
    – LPChip
    Commented 21 hours ago
  • PS C:\>dir /a dir : Cannot find path 'C:\a' because it does not exist. At line:1 char:1 + dir /a
    – LPChip
    Commented 21 hours ago
  • Also, upvoted the question. Its a valid question that does not need further information, although if the error had provided a bit more info, people would not have had to guess.
    – LPChip
    Commented 21 hours ago

1 Answer 1

1

Command prompt is indeed different to PowerShell.

dir is an internal command of Command Prompt and Powershell does not have this function.

Powershell has the cmdlet: get-childitem, which also gets all files in a folder, but has significant differences compared to cmd's dir function.

To make people get started quickly in powershell, they added the alias dir, ls and gci to the cmdlet get-childitem. This means that, even though you can type in dir in powershell, none of the parameters work the way they work in cmd. For example, in cmd, you can type dir /s, in powershell, you would type get-childitem -recurse. Because dir is an alias for get-childitem, you can also type dir -recurse.

It is true that all normal commands that you can run in cmd (calling .exe files) work natively in PowerShell. Dir however is not a program with .exe extension, but an internal function of cmd.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .