⚑ IT Wisdom Why did the DevOps engineer get divorced? He said "It's not you, it's the environment."
Skilled Practitioner
4249 XP 1751 to Expert
Objective: Use os.makedirs() to create a directory structure, then use glob to list files by extension.
Instructions

Run the following commands in your terminal to create a test directory with files:

mkdir -p lab10
touch lab10/sw-core-01.cfg lab10/rtr-edge-01.cfg lab10/fw-dmz-01.cfg
touch lab10/devices.json lab10/notes.txt

Then create lab1.py:

  1. Use glob.glob() to list all .cfg files in lab10/
  2. Print the count and each filename (basename only, not the full path)
  3. Use glob.glob() to list all .json files in lab10/
  4. Print the count and each filename

Your output must match exactly:

CFG files: 3
fw-dmz-01.cfg
rtr-edge-01.cfg
sw-core-01.cfg
JSON files: 1
devices.json

Run it with python3 lab1.py. Paste your output below and submit.

Starter Code
import glob
import os

cfg_files = sorted(glob.glob("lab10/*.cfg"))
print(f"CFG files: {len(cfg_files)}")
for f in cfg_files:
    print(os.path.basename(f))

json_files = sorted(glob.glob("lab10/*.json"))
print(f"JSON files: {len(json_files)}")
for f in json_files:
    print(os.path.basename(f))
πŸ’‘ Show Hint
Use sorted() on the glob result so files appear in alphabetical order. os.path.basename() strips the directory prefix and returns just the filename.
Paste Your Output
Next Lab β†’