List and count directories in a path by filtering list_dir results for directory entries and excluding hidden/system files
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-list-and-count-directories-f42dd04f9af2 ,按照其中的说明把「list-and-count-directories」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This skill provides a systematic workflow for listing and counting directories within a given path using the list_dir tool. It filters results to identify directories, excludes hidden and system entries, and presents both an enumerated list and a total count.
Use list_dir to retrieve the contents of the target path:
list_dir(path="/path/to/target")
Filter the results to identify directory entries. Directories are marked by permissions starting with d in Unix ls format (e.g., drwxr-xr-x).
Recognition pattern:
ddrwxr-xr-x, drwxrwxr-x, drwx------, etc.Filter out entries that should not be counted:
. (current directory).. (parent directory).DS_Store (macOS metadata). (optional, depending on requirements)Present the directories as a numbered list for easy reference:
1. directory-name-1
2. directory-name-2
3. directory-name-3
...
Calculate and report the total number of directories found:
Total: N directories
When implementing this workflow programmatically, use the following approach:
# Pseudo-code for filtering directories
directories = []
for entry in dir_listing:
# Check if entry is a directory (starts with 'd')
if entry['permissions'].startswith('d'):
name = entry['name']
# Exclude hidden/system entries
if name not in ['.', '..', '.DS_Store']:
directories.append(name)
# Sort for consistent ordering
directories.sort()
# Present enumerated list
for i, dirname in enumerate(directories, 1):
print(f"{i}. {dirname}")
# Provide total count
print(f"\nTotal: {len(directories)} directories")
Directories in /skills:
1. authentication-helpers
2. data-processing
3. workflow-automation
Total: 3 directories
Found 3 skill directories in /skills:
1. authentication-helpers
2. data-processing
3. workflow-automation
Directory inventory for /path/to/modules:
- module-a
- module-b
- module-c
Count: 3 directories
-)