1# Obtaining Application and File System Space Statistics 2 3This topic describes how to obtain information about the free system space and space occupied by applications so as to prevent insufficient storage space of the system or ensure proper use of quota-controlled **cacheDir** directories. 4 5## Available APIs 6 7For details about the APIs, see [ohos.file.statvfs](../reference/apis/js-apis-file-statvfs.md) and [ohos.file.storageStatistics](../reference/apis/js-apis-file-storage-statistics.md). 8 9**Table 1** APIs for file system and application space statistics 10 11| Module| API| Description| 12| -------- | -------- | -------- | 13| \@ohos.file.storageStatistic | getCurrentBundleStats | Obtains the storage space of the current application, in bytes.| 14| \@ohos.file.statvfs | getFreeSize | Obtains the free space of a file system, in bytes.| 15| \@ohos.file.statvfs | getTotalSize | Obtains the total space of a file system, in bytes.| 16 17**Table 2** Attributes for application space statistics 18 19| BundleStats Attribute| Description| Directory for Statistics| 20| -------- | -------- | -------- | 21| appSize | Size of the application installation files, in bytes.| Application installation file directory:<br>**/data/storage/el1/bundle **| 22| cacheSize | Size of the application cache files, in bytes.| Application cache file directories:<br>**/data/storage/el1/base/cache**<br>**/data/storage/el1/base/haps/entry/cache**<br>**/data/storage/el2/base/cache**<br>**/data/storage/el2/base/haps/entry/cache **| 23| dataSize | Size of the application files (excluding the application installation files and cache files), in bytes.| The application files include local files, distributed files, and database files.<br>- Local application file directories (parent directories of the **cache** directories):<br>**/data/storage/el1/base**<br>**/data/storage/el2/base**<br>- Distributed application directory:<br>/data/storage/el2/distributedfiles<br>- Database directories:<br>**/data/storage/el1/database**<br>**/data/storage/el2/database **| 24 25## Development Example 26 27- Obtain the free space of **/data** of the file system. 28 29 ```ts 30 import statvfs from '@ohos.file.statvfs'; 31 32 let path = "/data"; 33 statvfs.getFreeSize(path, (err, number) => { 34 if (err) { 35 console.error(`Invoke getFreeSize failed, code is ${err.code}, message is ${err.message}`); 36 } else { 37 console.info(`Invoke getFreeSize succeeded, size is ${number}`); 38 } 39 }); 40 ``` 41 42- Obtain the space occupied by the current application. 43 44 ```ts 45 import storageStatistics from "@ohos.file.storageStatistics"; 46 47 storageStatistics.getCurrentBundleStats((err, bundleStats) => { 48 if (err) { 49 console.error(`Invoke getCurrentBundleStats failed, code is ${err.code}, message is ${err.message}`); 50 } else { 51 console.info(`Invoke getCurrentBundleStats succeeded, appsize is ${bundleStats.appSize}`); 52 } 53 }); 54 ``` 55