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文件总数", "桶里有多少个文件", "统计文件数量", "对象数量", "查询对象总数".
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.
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
hcloud CLI (KooCLI) installed and authenticated — See references/cli-installation-guide.md
obsutil installed — required by the hcloud OBS ls command (bundled with KooCLI or standalone)
OBS credentials configured for obsutil — hcloud OBS ls reads AK/SK/endpoint from the obsutil config file
(.obsutilconfig in the user home directory), which is separate from the KooCLI account credentials
IAM permissions — obs:bucket:ListBucket, obs:object:List — See references/iam-policies.md
OBS credentials are separate. Before running, check whether obsutil credentials are configured:
bash
hcloud OBS ls -s -limit=1
If the output is Please set ak, sk and endpoint in the configuration file! or an InvalidAccessKeyId error,
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:
Example (cn-north-4): hcloud obs config -i=<YourAK> -k=<YourSK> -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=1 to 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:
# Force the CLI (hcloud OBS ls) path
python3 scripts/count_obs_files.py --bucket <bucket_name> --executor cli
# Force the SDK (huaweicloudsdkobs) path
python3 scripts/count_obs_files.py --bucket <bucket_name> --executor sdk
# Explicit region (default: cn-north-4)
python3 scripts/count_obs_files.py --bucket <bucket_name> --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)
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 ls command is an obsutil-backed wrapper. Bucket/endpoint
targeting is configured in the obsutil config file (.obsutilconfig in the user home directory), so --cli-region is not used for
this command; the equivalent region control is the obsutil endpoint setting.
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: