Get directory capacity overview
Updated at:2025-11-03
Users can get the current capacity, number of objects, and number of files under a bucket or a specified prefix through the following code. Here, the term “file” refers to ordinary files, excluding folders, let alone directories in the logical sense of delimiters. An “object” is the number of keys actually stored in the bucket. That is, the number of files is equal to the number of objects minus the number of objects ending with a delimiter. For example, if there are 9 objects in the current directory, 5 of which are folders and 4 are files, then the number of files found is 4, and the number of objects is 9.
Java
1public void stateSummary(BosClient client, String bucketName, String prefix) {
2 // Get the current capacity, number of objects, and number of files under the bucket
3 StateSummaryResponse response = client.stateSummary(bucketName);
4 System.out.println("currSize : " + response.getTotalSize());
5 System.out.println("objectsCount : " + response.getObjectsCount());
6 System.out.println("filesCount : " + response.getFilesCount());
7}
Get the capacity, number of objects, and number of files of objects with a specified prefix:
Java
1public StateSummaryResponse stateSummaryWithPrefix(BosClient client, String bucketName, String prefix) {
2 StateSummaryRequest request = new StateSummaryRequest();
3 request.setBucketName(this.bucketName);
4 request.setPrefix("dir/x");
5 StateSummaryResponse response = client.stateSummary(request);
6 return response;
7}
