I have this folder:
sa
that has folders a
,b
,c
. These folders have folders:
PST
and DBOUND
.
If for example folder b
has empty pst
folder and existing dbounds
, the following code should NOT append contents from that folder at all and skip it.
code:
import geopandas as gpd
from glob import glob
ps=[]
db=[]
for i in glob(r'C:\Users\user\Desktop\sa' + '**/*/*/*', recursive=True):
if i.endswith('PST.shp'):
ps.append(i)
if i.endswith('DBOUND.shp'):
db.append(i)
How to make it not append from a folder, if their subfolder has either PST
or DBOUND
folders empty? and append only from folders that have all the needed subfolders there?
Explanation
To help you understand:
If all the folders a
and b
are ok it returns this:
C:\Users\user\Desktop\sa\a\DBOUND\DBOUND.shp
C:\Users\user\Desktop\sa\a\PST\PST.shp
C:\Users\user\Desktop\sa\b\DBOUND\DBOUND.shp
C:\Users\user\Desktop\sa\b\PST\PST.shp
If c
has empty either PST
or DBOUND
folders, it should not appear at all in the list. It should skip the folder and not append it.