The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

List Sub-Directories (Excluding Hidden Ones) Non-Recursively In Python

TODO: Pull subtitle into page object

Note that this just gives you the names. No extra paths come through.

This code:

code_start_default_section code_end_default_section

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

List Sub-Directories (Excluding Hidden Ones) Non-Recursively In Python

-- p

Note that this just gives you the names. No extra paths come through.

-- p

This code:

-- code/
-- python

from os import listdir
from os.path import isdir
from os.path import join

source_dir = "example_dir"

directories = [d for d in listdir(source_dir) if isdir(join(source_dir, d)) and d[0] != '.' ]

print(directories)

-- /code

-- p

Will return this:

-- code/
-- txt

['dir-2', 'dir-1']

-- /code

-- p

Given a directory tree like:

-- code/
-- txt

example_dir
├── .invisible-dir
│   ├── file-10.txt
│   └── file-9.txt
├── .invisible-file-1.txt
├── .invisible-file-2.txt
├── dir-1
│   ├── file-3.txt
│   └── file-4.txt
├── dir-2
│   ├── dir-3
│   │   ├── file-7.txt
│   │   └── file-8.txt
│   ├── file-5.txt
│   └── file-6.txt
├── file-1.txt
└── file-2.txt

-- /code


-- categories
-- Python

-- metadata
-- date: 2022-03-10 22:27:27
-- id: 26drxzxy
-- status: published
-- type: post
-- SCRUBBED_NEO: false
-- site: aws