• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.statfs (statfs)
2
3The **statfs** module provides APIs for obtaining file system information, including the total number of bytes and the number of idle bytes of the file system.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> - The APIs provided by this module are deprecated since API version 9. You are advised to use [@ohos.file.statvfs](js-apis-file-statvfs.md).
10
11## Modules to Import
12
13```ts
14import statfs from '@ohos.statfs';
15```
16## statfs.getFreeBytes
17
18getFreeBytes(path:string):Promise<number>
19
20Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
21
22**System capability**: SystemCapability.FileManagement.File.FileIO
23
24**Parameters**
25
26  | Name| Type  | Mandatory| Description                        |
27  | ------ | ------ | ---- | ---------------------------- |
28  | path   | string | Yes  | File path of the file system.|
29
30**Return value**
31
32  | Type                 | Description          |
33  | --------------------- | -------------- |
34  | Promise<number> | Promise used to return the number of free bytes obtained.|
35
36**Example**
37
38  ```ts
39  import { BusinessError } from '@ohos.base';
40  let path = "/dev";
41  statfs.getFreeBytes(path).then((number: number) => {
42    console.info("getFreeBytes promise successfully:" + number);
43  }).catch((err: BusinessError) => {
44    console.info("getFreeBytes failed with error:" + JSON.stringify(err));
45  });
46  ```
47
48## statfs.getFreeBytes
49
50getFreeBytes(path:string, callback:AsyncCallback<number>): void
51
52Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
53
54**System capability**: SystemCapability.FileManagement.File.FileIO
55
56**Parameters**
57
58  | Name  | Type                       | Mandatory| Description                        |
59  | -------- | --------------------------- | ---- | ---------------------------- |
60  | path     | string                      | Yes  | File path of the file system.|
61  | callback | AsyncCallback<number> | Yes  | Callback invoked to return the number of free bytes obtained.|
62
63**Example**
64
65  ```js
66  import featureAbility from '@ohos.ability.featureAbility';
67  let context = featureAbility.getContext();
68  context.getFilesDir().then(function (path) {
69      statfs.getFreeBytes(path, function (err, number) {
70          console.info("getFreeBytes callback successfully:" + number);
71      });
72  });
73  ```
74
75## statfs.getTotalBytes
76
77getTotalBytes(path: string): Promise<number>
78
79Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
80
81**System capability**: SystemCapability.FileManagement.File.FileIO
82
83**Parameters**
84
85  | Name| Type  | Mandatory| Description                        |
86  | ---- | ------ | ---- | ---------------------------- |
87  | path | string | Yes  | File path of the file system.|
88
89**Return value**
90
91  | Type                 | Description        |
92  | --------------------- | ------------ |
93  | Promise<number> | Promise used to return the total number of bytes obtained.|
94
95**Example**
96
97  ```ts
98  import { BusinessError } from '@ohos.base';
99  let path = "/dev";
100  statfs.getTotalBytes(path).then((number: number) => {
101    console.info("getTotalBytes promise successfully:" + number);
102  }).catch((err: BusinessError) => {
103    console.info("getTotalBytes failed with error:" + JSON.stringify(err));
104  });
105  ```
106
107## statfs.getTotalBytes
108
109getTotalBytes(path: string, callback: AsyncCallback<number>): void
110
111Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
112
113**System capability**: SystemCapability.FileManagement.File.FileIO
114
115**Parameters**
116
117  | Name  | Type                       | Mandatory| Description                        |
118  | -------- | --------------------------- | ---- | ---------------------------- |
119  | path     | string                      | Yes  | File path of the file system.|
120  | callback | AsyncCallback<number> | Yes  | Callback invoked to return the total number of bytes obtained.  |
121
122**Example**
123
124  ```js
125  import featureAbility from '@ohos.ability.featureAbility';
126  let context = featureAbility.getContext();
127  context.getFilesDir().then(function (path) {
128      statfs.getTotalBytes(path, function(err, number) {
129          console.info("getTotalBytes callback successfully:" + number);
130      });
131  });
132  ```
133