简体   繁体   中英

Powershell dir command options not working

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:

Example

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.

here is how I will bring out all the files in.cpp. Here is a small program in powershell:

$path = "C:\temp\"
$filter = "*.cpp"

$files = Get-ChildItem -Path $path -Filter $filter

Write-Host "here, all the .cpp files in '$path' :"
Write-Host $files -Separator "`r`n"

I prefer to use the cmdlet "Get-ChildItem" rather than "dir".

Here the content folder for my test

And, why so many /?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM