Here are a few ways to list all subdirectories in the current directory:
Using the Command Line
– Windows:
– dir /ad (lists only directories)
– dir /ad /b (lists only directories, bare format)
– macOS/Linux:
– ls -d / (lists only directories)
– find. -max depth 1 -type d (lists only directories in the current directory)
Using Programming Languages
– Python:
python, import os
subdirectories = [d for in os.list dir (‘.’) if os.path.is dir (d)]
print(subdirectories)
JavaScript (Node.js):
javascript
const fs = require(‘fs’)
const path = require(‘path’)
const subdirectories = fs.readdir Sync(‘.’).filter (d => fs.stat Sync (path.join (‘.’, d)).is Directory ());
console.log(subdirectories);
– Java:
java
import java.io.File;
import java.util.Arrays;
File[] subdirectories = new File(“.”).list Files(File: is Directory)
System. out .print ln (Arrays.to String (subdirectories))