简体   繁体   中英

Trying to Exclude a Folder with -Recursive search in get-childitem

I am new to PowerShell...

SL D:\\SomeFolder get-childitem -exclude <D:\\Somefolder\\A> -recurse -Directory

I don't want d:\\somefolder\\A and its contents in the results, but for rest of the directories in "somefolder" I want recursive results.

I tried the command above, however, it is going inside the "\\A" directory. It may be happening due to the -recurse switch, because if I don't use it...

Is there another way to achieve this?

This lists children folders of D:\\SomeFolder without D:\\Somefolder\\A:

get-childitem 'D:\SomeFolder' -recurse -Directory ` 
  | ? { $_.FullName -notlike 'D:\Somefolder\A*' }

See also here

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