The "dir"-command (alias for get-childitem) in PowerShell does have some differences from dir in cmd.exe. It's more powerful, but it also takes more typing.
One of the things that might strike some people as odd is that "dir *.txt -recurse" doesn't work as "dir *.txt /s" in cmd.exe. The reason to this is that in PowerShell you actually use 2 parameters for this type of command.
- Where to look
- What to look for
So, what you should write is:
PS#> dir . *.txt -recurse (noticed the lonely dot?)
What this is saying is: Look for all *.txt-files in the current (.) directory, and subdirectories.
But, hey! Then why does "dir *.txt" (without -recurse) work the way you would think? Well "where to look" can include files.
The thing is that the pattern "*.txt" doesn't very often include any directories. In fact, if you would have a directory named "mydirectory.txt"; then "dir *.txt -r" would return all files in that directory and subdirectories, not only .txt-files. (Because "what to look for" hasn't been specified)
Posted
08-07-2007 15:18
by
bjorn.osterman