I was trying to use dir command to list recursively all files that end with .cpp in a given directory, I tried to follow various solutions but my powershell seems not to accept any options after '/' sign as seen on the picture bellow:
The command I initially tried was 'dir sourcefolder "*.cpp"' but it only lists files in a given folder (because I cant provide any additional options as seen in microsoft doc), also any example command provided there does not work for me giving the same error as shown in example above.
dir
isn't the same as it is in cmd.exe. In PowerShell, it's an alias forGet-ChildItem
where the parameters begin with a dash (-
); this doesn't apply to positional parameters but is needed for switch parameters (unless it's being "splatted"). So, it would be:dir sourcefolder "*.cpp" -Recurse
. You can also runGet-Help dir
for more information about the cmdlet.cmd.exe /c 'dir ...'
from within PowerShell but there's really no point. Different shell, different syntax. Just includes aliases that are common across different shells for an easier transition into PowerShell with the major difference being it's an OO shell.