Counts the number of directories (folders) inside a Huawei Cloud OBS (Object Storage Service) bucket and returns ONLY the numeric count. Supports counting the immediate subdirectories under the bucket (or a given prefix) as well as all nested directories recursively. Uses the KooCLI obsutil-backed `hcloud OBS ls -d` command (primary) or the huaweicloudsdkobs Python SDK (fallback). Read-only — never creates, modifies or deletes any resource. Use this skill whenever the user wants to know how many directories/folders an OBS bucket contains, e.g. for inventory, capacity review or structure checks. Triggers include: "count OBS directories", "OBS directory count", "number of directories in bucket", "OBS folder count", "how many folders in bucket", "OBS目录数量", "查询OBS目录数量", "OBS目录数", "桶目录数量", "目录数量", "文件夹数量", "统计目录", "目录统计".
Memory
huawei-cloud-obs-file-count
Try itCounts the total number of files (objects) inside a Huawei Cloud OBS (Object Storage Service) bucket and returns ONLY the numeric count. Supports counting all files in a whole bucket or all files under a given prefix (folder). Zero-byte folder-marker keys (ending with '/') are excluded — only real files/objects are counted. Uses the KooCLI obsutil-backed `hcloud OBS ls ... -limit=0` command (primary, parses the "File number" line) or the huaweicloudsdkobs Python SDK (fallback, paginated ListObjects). Read-only — never creates, modifies or deletes any resource. Use this skill whenever the user wants to know how many files or objects an OBS bucket (or a folder inside it) contains, e.g. for inventory, capacity review, migration planning or compliance checks. Triggers include: "count OBS files", "OBS file count", "number of files in bucket", "how many objects in bucket", "OBS object count", "OBS文件数量", "查询OBS文件总数", "OBS文件总数", "桶里有多少个文件", "统计文件数量", "对象数量", "查询对象总数".
What it does
Counts the total number of files (objects) inside a Huawei Cloud OBS (Object Storage Service) bucket and returns ONLY the numeric count. Supports counting all files in a whole bucket or all files under a given prefix (folder). Zero-byte folder-marker keys (ending with '/') are excluded — only real files/objects are counted. Uses the KooCLI obsutil-backed `hcloud OBS ls ... -limit=0` command (primary, parses the "File number" line) or the huaweicloudsdkobs Python SDK (fallback, paginated ListObjects). Read-only — never creates, modifies or deletes any resource. Use this skill whenever the user wants to know how many files or objects an OBS bucket (or a folder inside it) contains, e.g. for inventory, capacity review, migration planning or compliance checks. Triggers include: "count OBS files", "OBS file count", "number of files in bucket", "how many objects in bucket", "OBS object count", "OBS文件数量", "查询OBS文件总数", "OBS文件总数", "桶里有多少个文件", "统计文件数量", "对象数量", "查询对象总数".
The skill document
Huawei Cloud OBS File Count Skill
Overview
This skill counts the number of files (objects) in a Huawei Cloud OBS bucket and returns only the count (a single integer). It is a read-only statistics skill: it never creates, modifies, or deletes buckets, directories, or objects.
Architecture:
Agent → hcloud CLI (KooCLI OBS / obsutil, primary) → Huawei Cloud OBS API
↘ huaweicloudsdkobs Python SDK (fallback) ↗
Two counting scopes:
| Scope | Description | Example |
|---|---|---|
| Whole bucket (default) | Total number of files in the entire bucket | --bucket my-bucket → 1827 |
| Under a prefix | Total number of files under one folder/prefix | --bucket my-bucket --prefix photos → 42 |
What counts as a file: an object whose key does not end with a slash. Zero-byte folder-marker keys —
keys whose name ends in a slash (e.g. photos) — are directory markers, not files, and are excluded
automatically by both executors.
Applicable Scenarios:
- Inventory: "how many files does this bucket hold?"
- Migration planning: estimate object count before moving data
- Cost review: object-count-based billing estimates
- Compliance auditing: detect unexpected file volumes
能力边界(Capability Boundary): 本 Skill 仅统计文件/对象数量,不统计目录(文件夹)数量、不统计总存储大小、不统计流量。 若用户询问"桶里有多少个目录/文件夹",请引导使用目录统计类 OBS 技能;若询问总存储量或流量, 请引导使用容量/统计类 OBS 技能或华为云控制台 OBS 监控页。
Prerequisites
- hcloud CLI (KooCLI) installed and authenticated — See
references/cli-installation-guide.md - obsutil installed — required by the
hcloud OBS lscommand (bundled with KooCLI or standalone) - OBS credentials configured for obsutil —
hcloud OBS lsreads AK/SK/endpoint from the obsutil config file (.obsutilconfigin the user home directory), which is separate from the KooCLI account credentials - Python 3.8+ with
huaweicloudsdkobspackage (SDK fallback) —pip install huaweicloudsdkobs - IAM permissions —
obs:bucket:ListBucket,obs:object:List— Seereferences/iam-policies.md
OBS credentials are separate. Before running, check whether obsutil credentials are configured:
hcloud OBS ls -s -limit=1If the output is
Please set ak, sk and endpoint in the configuration file!or anInvalidAccessKeyIderror, obsutil credentials are not configured. Ask the user to configure them in their own terminal (never ask the user to paste AK/SK into the conversation). Provide the following example command:hcloud obs config -i= -k= -e=obs..myhuaweicloud.comExample (cn-north-4):
hcloud obs config -i= -k= -e=obs.cn-north-4.myhuaweicloud.com
Workflow
- Confirm the scope — ask the user which OBS bucket to inspect, and optionally a subdirectory prefix
- Verify prerequisites —
hcloud version,hcloud OBS ls -s -limit=1to confirm obsutil credentials - Run the count — use the script
scripts/count_obs_files.py(primary) with the appropriate flags - Return the count — the script prints a single integer; relay that integer to the user
- Handle errors — if the script fails (e.g. bucket not found, invalid AK/SK, missing credentials), the script prints a clear Chinese error hint on stderr with configuration guidance; relay that hint to the user
Core Commands
Count All Files in a Bucket (Primary)
Returns the total number of files in the whole bucket:
python3 scripts/count_obs_files.py --bucket
Count Files Under a Prefix
Returns the total number of files under a folder/prefix (the prefix itself is normalized: a trailing slash is optional):
python3 scripts/count_obs_files.py --bucket --prefix
Example:
python3 scripts/count_obs_files.py --bucket my-bucket --prefix photos
Force a Specific Executor
# Force the CLI (hcloud OBS ls) path
python3 scripts/count_obs_files.py --bucket --executor cli
# Force the SDK (huaweicloudsdkobs) path
python3 scripts/count_obs_files.py --bucket --executor sdk
# Explicit region (default: cn-north-4)
python3 scripts/count_obs_files.py --bucket --region cn-east-3
The default --executor auto tries the CLI first and falls back to the SDK only for
infrastructure errors (missing hcloud binary, timeout). Definitive service errors
(NoSuchBucket, AccessDenied, InvalidAccessKeyId) are reported directly with a clear
Chinese hint instead of triggering a fallback.
Parameter Confirmation
| Parameter | Required | Description | Example |
|---|---|---|---|
--bucket | Yes | OBS bucket name | my-bucket |
--prefix | No | Count files under this prefix/folder only (trailing slash optional) | photos |
--region | No | Huawei Cloud region (default cn-north-4) | cn-east-3 |
--executor | No | auto (default) | cli | sdk | sdk |
KooCLI Command Format Standard
hcloud --cli-region= [--key=value ...]
| Feature | Description | Example |
|---|---|---|
| Service name | Exact KooCLI Service name beginning with uppercase/title case | OBS |
| Operation name | PascalCase | ls (obsutil command) |
| Region parameter | Endpoint configured via obsutil config, not --cli-region | -e=obs.cn-north-4.myhuaweicloud.com |
| Simple parameter | --key=value | -limit=0 |
Note: the
hcloud OBS lscommand is an obsutil-backed wrapper. Bucket/endpoint targeting is configured in the obsutil config file (.obsutilconfigin the user home directory), so--cli-regionis not used for this command; the equivalent region control is the obsutilendpointsetting.
Verification Method
See references/verification-method.md for full verification steps, and
references/acceptance-criteria.md for the acceptance checklist. The bundled
test script runs a functional smoke test:
bash scripts/test-cli-commands.sh
Reference Documents
references/cli-installation-guide.md— hcloud (KooCLI) and obsutil installation, obsutil credential configuration, troubleshootingreferences/iam-policies.md— least-privilege IAM policy (read-only)references/verification-method.md— CLI/SDK cross-check verification stepsreferences/dataflow-diagram.md— Mermaid architecture and sequence diagramsreferences/acceptance-criteria.md— functional, security and quality acceptance criteria
Related skills
Queries the total storage size of Huawei Cloud OBS (Object Storage Service) buckets and returns ONLY the size value — a single number, in bytes by default. Supports querying the total size of one bucket or the combined total across all buckets under the account. Uses the KooCLI obsutil-backed `hcloud OBS ls ... -du -bf=raw` command (primary) or the huaweicloudsdkobs Python SDK (fallback). Read-only — never creates, modifies or deletes any resource. Use this skill whenever the user wants to know the total size of an OBS bucket or the overall OBS storage usage, e.g. for capacity review, cost estimation or storage planning. Triggers include: OBS total size, OBS bucket size, total storage usage, bucket capacity, OBS大小, OBS总大小, OBS容量, 桶大小, 查询OBS大小, 存储占用, OBS存储量.
Query Huawei Cloud OBS (Object Storage Service) statistics: list buckets with capacity and object counts, query extranet/intranet download traffic with month...
Lists the Huawei Cloud OBS (Object Storage Service) buckets of the current tenant and returns the FOLDER names inside a bucket — both the top-level folders of a bucket and the sub-folders under a given prefix. Uses the KooCLI obsutil-backed command `hcloud OBS ls` (primary, parses the "Folder list" section of obsutil output) or the huaweicloudsdkobs Python SDK (fallback, ListObjects with delimiter=/). Read-only — never creates, modifies or deletes any bucket, folder or object. Use this skill whenever the user wants to see which OBS buckets exist or which folders a bucket (or a folder inside it) contains, e.g. for daily inspection, inventory, data organization review or troubleshooting. Triggers include: "list OBS buckets", "OBS bucket list", "list folders in bucket", "OBS folder names", "查询OBS列表", "OBS桶列表", "OBS文件夹名称", "桶里有哪些文件夹", "查询obs列表", "返回obs列表中文件夹名称", "OBS目录列表".
Upload local files or directories to Huawei Cloud OBS (Object Storage Service) buckets, list OBS buckets with capacity and object count, and schedule periodic uploads via crontab. Use this skill when the user wants to: (1) upload a local file or directory to an OBS bucket, (2) list OBS buckets and check their storage capacity and object count, (3) set up a scheduled/periodic upload task to automatically sync a local directory to an OBS bucket. Trigger: user mentions "OBS", "object storage", "bucket list", "bucket capacity", "upload to OBS", "upload file", "upload directory", "scheduled upload", "periodic upload", "sync to bucket", "对象存储", "桶列表", "桶容量", "上传文件", "上传目录", "定时上传", "OBS管理"
Queries Huawei Cloud storage resources (EVS/OBS/SFS/CBR). Covers cloud disks (volumes/snapshots/types/quotas/recycle bin), OBS buckets (ACL/metadata/notifica...