Wednesday, January 15, 2025
HomeGeneralWhat Command or Code can I use to list all Subdirectories in...

What Command or Code can I use to list all Subdirectories in the Current Directory?

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))
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x