'Print names of directories that are missing a specific subdirectory

I have 3 directories (sub01, sub02, and sub03) where each individual has 3 different visits (visit1, visit2, visit3). Within a few of these visit directories, is an additional subdirectory, we'll call it Psych_Measure.

I have been able to easily print the paths of those who have the Psych_Measure by using:

psych = glob.glob("sub*/visit*/Psych_Measure");

However, I also want a list of the paths for those individuals' visits who are missing the Psych_Measure while ignoring other variables in this subdirectory (Data.Description & Date). For example: if the path sub01/visit2/Psych_Measure exists, I want those paths to be in a list and if it doesn't exist (sub01/visit1/(does not contain psych measures), then I want this path in a different list representing those paths that do not contain Psych_Measures. How can I do that? I have tried to run an if-else statement, but have been very unsuccessful.



Solution 1:[1]

You could replace Psych_Measure with a wildcard itself, i.e.,

sub*/visit*/*

If there are any directories you know you don't want, you could add a conditional to exclude those if there's no clean way to establish the wildcard

i.e.,

sub*/visit*/[!Psych_Measure]*

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bussller