Get a list of directories without a given subdirectory

Suppose I have a directory tree like the following:

 |-- Store1
 |   |-- Clients
 |   |-- Orders
 |-- Store2
 |   |-- Clients
 |   |-- Orders
 |-- Store3
 |   |-- Clients
 |-- Store4
 |   |-- Clients
 
i.e., some directories have an "Orders" subdirectory and others don't. I would like a Windows Powershell script to get a list of all the directories which have no "Orders" subdirectory, and output the results to a file. This is similar to my previous question "Get list of nonempty directories".

I am using Windows 7.
RothbardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subash SundharanIT Infrastructure Architect Commented:
Try..
GCI "C:\Folder" | ?{$_.PSIsContainer} |%{
	If (!(GCI $_.FullName | ?{$_.PSIsContainer -and $_.Name -eq "Orders"})){
	$_.FullName
	}
}| Out-file C:\Temp\result.txt

Open in new window

result.txt file will have the full path of the folders which doesn't have Orders folder..
1
oBdACommented:
Get-ChildItem -Path D:\AllStores -Directory | ? {!(Get-ChildItem -Path $_.FullName -Filter "Orders")}

Open in new window

You can pipe the result through additional Select-Object and finally to Set-Content as needed, for example like this:
Get-ChildItem -Path D:\AllStores -Directory | ? {!(Get-ChildItem -Path $_.FullName -Filter "Orders")} | Select-Object -ExpandProperty FullName | Set-Content -Path D:\Temp\test.log

Open in new window

1
Brent ChallisPrincipal: ITCommented:
The following script assumes that you are only looking one folder down from the base folder.

$folderBase = "C:\Stores"
$reportFileName = "c:\Stores\report.txt"
$subFolderNames = Get-ChildItem $folderBase -Directory | Select-Object -ExpandProperty FullName

#Initialise file with a time stamp
("Report on folders without the Orders subfolder run at {0}"-f (Get-Date)) | Out-File $reportFileName

foreach ($subfolderName in $subFolderNames)
{
    if (Test-Path "$subfolderName\Orders")
    {
        Write-Verbose "Orders found in $subfolderName"
    }
    else
    {
        $subfolderName | Out-File $reportFileName -Append
    }
}
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.