Powershell Return packages that contain a specific file but not fully recursive

Using the following Powershell code, I am trying to find folders that DO NOT contain robots.txt in the root. Typically, I could do this recursively, but he adopted FOREVER to restore this massive folder structure. I really need only the first level, AKA is only looking for folders found in C: \ Projects.

Basically, I need to get children from each set of children, and only then return them to parents where there was no robots.txt file. The problem I came across here is my $ _ in a nested loop that gives me CWD, and not the children of the directory I'm looking for. I know that I may have to use "Somewhere here, but I'm a little overhead and quite new to powershell. Any help is appreciated!

$drv = gci C:\Projects | %{ $parent = $_; gci -exclude "robots.txt" | %{$_.parent}} | gu 
+4
source share
1 answer

this single-line font (across multiple cells for clarity) should do the trick for you:

 # look directly in projects, not recursively dir c:\projects | where { # returns true if $_ is a container (ie a folder) $_.psiscontainer } | where { # test for existence of a file called "robots.txt" !(test-path (join-path $_.fullname "robots.txt")) } | foreach { # do what you want to do here with $_ "$($_.fullname) does not have robots.txt" } 
+6
source

All Articles