提交 5ebdf5fa 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 6ae9646b
...@@ -218,8 +218,8 @@ ...@@ -218,8 +218,8 @@
- [@ohos.file.statvfs (File System Space Statistics)](js-apis-file-statvfs.md) - [@ohos.file.statvfs (File System Space Statistics)](js-apis-file-statvfs.md)
- [@ohos.filemanagement.userFileManager (User Data Management)](js-apis-userFileManager.md) - [@ohos.filemanagement.userFileManager (User Data Management)](js-apis-userFileManager.md)
- [@ohos.multimedia.medialibrary (Media Library Management)](js-apis-medialibrary.md) - [@ohos.multimedia.medialibrary (Media Library Management)](js-apis-medialibrary.md)
- [@ohos.storageStatistics (Application Storage Statistics)](js-apis-storage-statistics.md) - [@ohos.file.storageStatistics (Application Storage Statistics)](js-apis-file-storage-statistics.md)
- [@ohos.volumeManager (Volume Management)](js-apis-volumemanager.md) - [@ohos.file.volumeManager (Volume Management)](js-apis-file-volumemanager.md)
- Telephony Service - Telephony Service
- [@ohos.contact (Contacts)](js-apis-contact.md) - [@ohos.contact (Contacts)](js-apis-contact.md)
- [@ohos.telephony.call (Call)](js-apis-call.md) - [@ohos.telephony.call (Call)](js-apis-call.md)
......
...@@ -198,18 +198,23 @@ Creates an app account implicitly based on the specified account owner. This API ...@@ -198,18 +198,23 @@ Creates an app account implicitly based on the specified account owner. This API
**Example** **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) { function onResultCallback(code, result) {
console.log("resultCode: " + code); console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result)); console.log("result: " + JSON.stringify(result));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request}; let wantInfo = {
featureAbility.startAbility(abilityStartSetting, (err) => { deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err)); console.log("startAbility err: " + JSON.stringify(err));
}); })
} }
try { try {
...@@ -252,18 +257,23 @@ Creates an app account implicitly based on the specified account owner and optio ...@@ -252,18 +257,23 @@ Creates an app account implicitly based on the specified account owner and optio
**Example** **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) { function onResultCallback(code, result) {
console.log("resultCode: " + code); console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result)); console.log("result: " + JSON.stringify(result));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request}; let wantInfo = {
featureAbility.startAbility(abilityStartSetting, (err) => { deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err)); console.log("startAbility err: " + JSON.stringify(err));
}); })
} }
let options = { let options = {
...@@ -1346,7 +1356,7 @@ Authenticates an app account. This API uses an asynchronous callback to return t ...@@ -1346,7 +1356,7 @@ Authenticates an app account. This API uses an asynchronous callback to return t
**Example** **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, authResult) { function onResultCallback(code, authResult) {
console.log("resultCode: " + code); console.log("resultCode: " + code);
...@@ -1354,10 +1364,17 @@ Authenticates an app account. This API uses an asynchronous callback to return t ...@@ -1354,10 +1364,17 @@ Authenticates an app account. This API uses an asynchronous callback to return t
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request}; let wantInfo = {
featureAbility.startAbility(abilityStartSetting, (err) => { deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err)); console.log("startAbility err: " + JSON.stringify(err));
}); })
} }
try { try {
...@@ -1402,7 +1419,7 @@ Authenticates an app account with customized options. This API uses an asynchron ...@@ -1402,7 +1419,7 @@ Authenticates an app account with customized options. This API uses an asynchron
**Example** **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, authResult) { function onResultCallback(code, authResult) {
console.log("resultCode: " + code); console.log("resultCode: " + code);
...@@ -1410,10 +1427,17 @@ Authenticates an app account with customized options. This API uses an asynchron ...@@ -1410,10 +1427,17 @@ Authenticates an app account with customized options. This API uses an asynchron
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request}; let wantInfo = {
featureAbility.startAbility(abilityStartSetting, (err) => { deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err)); console.log("startAbility err: " + JSON.stringify(err));
}); })
} }
let options = { let options = {
...@@ -2706,7 +2730,7 @@ Adds an app account. This API uses an asynchronous callback to return the result ...@@ -2706,7 +2730,7 @@ Adds an app account. This API uses an asynchronous callback to return the result
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------------- | | -------- | ------------------------- | ---- | -------------------- |
| name | string | Yes | Name of the target app account. | | name | string | Yes | Name of the app account to add. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Example** **Example**
...@@ -2724,6 +2748,7 @@ addAccount(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;) ...@@ -2724,6 +2748,7 @@ addAccount(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;)
Adds an app account name and additional information. This API uses an asynchronous callback to return the result. Adds an app account name and additional information. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-1). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-1).
**System capability**: SystemCapability.Account.AppAccount **System capability**: SystemCapability.Account.AppAccount
...@@ -2750,8 +2775,7 @@ addAccount(name: string, extraInfo?: string): Promise&lt;void&gt; ...@@ -2750,8 +2775,7 @@ addAccount(name: string, extraInfo?: string): Promise&lt;void&gt;
Adds an app account name and additional information. This API uses an asynchronous callback to return the result. This API uses a promise to return the result. Adds an app account name and additional information. This API uses an asynchronous callback to return the result. This API uses a promise to return the result.
> **NOTE** > **NOTE**<br>
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-2). > This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-2).
**System capability**: SystemCapability.Account.AppAccount **System capability**: SystemCapability.Account.AppAccount
...@@ -2803,7 +2827,7 @@ Adds an app account implicitly based on the specified owner. This API uses an as ...@@ -2803,7 +2827,7 @@ Adds an app account implicitly based on the specified owner. This API uses an as
**Example** **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) { function onResultCallback(code, result) {
console.log("resultCode: " + code); console.log("resultCode: " + code);
...@@ -2811,10 +2835,17 @@ Adds an app account implicitly based on the specified owner. This API uses an as ...@@ -2811,10 +2835,17 @@ Adds an app account implicitly based on the specified owner. This API uses an as
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request}; let wantInfo = {
featureAbility.startAbility(abilityStartSetting, (err)=>{ deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err)); console.log("startAbility err: " + JSON.stringify(err));
}); })
} }
appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, { appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, {
...@@ -2839,7 +2870,7 @@ Deletes an app account. This API uses an asynchronous callback to return the res ...@@ -2839,7 +2870,7 @@ Deletes an app account. This API uses an asynchronous callback to return the res
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | ---------------- |
| name | string | Yes | Name of the target app account. | | name | string | Yes | Name of the app account to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Example** **Example**
...@@ -2866,7 +2897,7 @@ Deletes an app account. This API uses a promise to return the result. ...@@ -2866,7 +2897,7 @@ Deletes an app account. This API uses a promise to return the result.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- | | ---- | ------ | ---- | ----------- |
| name | string | Yes | Name of the target app account.| | name | string | Yes | Name of the app account to delete.|
**Return value** **Return value**
...@@ -3751,18 +3782,23 @@ Authenticates an app account with customized options. This API uses an asynchron ...@@ -3751,18 +3782,23 @@ Authenticates an app account with customized options. This API uses an asynchron
**Example** **Example**
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) { function onResultCallback(code, result) {
console.log("resultCode: " + code); console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result)); console.log("result: " + JSON.stringify(result));
} }
function onRequestRedirectedCallback(request) { function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request}; let wantInfo = {
featureAbility.startAbility(abilityStartSetting, (err)=>{ deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.log("startAbility successfully");
}).catch((err) => {
console.log("startAbility err: " + JSON.stringify(err)); console.log("startAbility err: " + JSON.stringify(err));
}); })
} }
appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, { appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, {
...@@ -4521,10 +4557,13 @@ Enumerates the constants. ...@@ -4521,10 +4557,13 @@ Enumerates the constants.
| KEY_REQUIRED_LABELS<sup>9+</sup> | "requiredLabels" | Required labels. | | KEY_REQUIRED_LABELS<sup>9+</sup> | "requiredLabels" | Required labels. |
| KEY_BOOLEAN_RESULT<sup>9+</sup> | "booleanResult" | Return value of the Boolean type. | | KEY_BOOLEAN_RESULT<sup>9+</sup> | "booleanResult" | Return value of the Boolean type. |
## ResultCode<sup>8+</sup> ## ResultCode<sup>(deprecated)</sup>
Enumerates the result codes. Enumerates the result codes.
> **NOTE**
> This enum is supported since API version 8 and deprecated since API version 9. From API version 9, error codes are used. For details about the error codes, see [App Account Error Codes](../errorcodes/errorcode-app-account.md).
**System capability**: SystemCapability.Account.AppAccount **System capability**: SystemCapability.Account.AppAccount
| Name | Value | Description | | Name | Value | Description |
...@@ -4760,7 +4799,7 @@ Creates an app account implicitly based on the specified account owner. This API ...@@ -4760,7 +4799,7 @@ Creates an app account implicitly based on the specified account owner. This API
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------------- | --------------------- | ---- | --------------- | | ---------------- | --------------------- | ---- | --------------- |
| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. | | options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating an account. |
| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| | callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.|
### addAccountImplicitly<sup>(deprecated)</sup> ### addAccountImplicitly<sup>(deprecated)</sup>
......
...@@ -5,6 +5,7 @@ The **fs** module provides APIs for file operations, including basic file manage ...@@ -5,6 +5,7 @@ The **fs** module provides APIs for file operations, including basic file manage
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). > - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import ## Modules to Import
...@@ -15,7 +16,7 @@ import fs from '@ohos.file.fs'; ...@@ -15,7 +16,7 @@ import fs from '@ohos.file.fs';
## Guidelines ## Guidelines
Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the application sandbox as follows: Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the file or directory in the application sandbox as follows:
**Stage Model** **Stage Model**
...@@ -147,7 +148,7 @@ Checks whether a file exists. This API uses a promise to return the result. ...@@ -147,7 +148,7 @@ Checks whether a file exists. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return a Boolean value. | | Promise&lt;boolean&gt; | Promise used to return a Boolean value.|
**Example** **Example**
...@@ -1079,7 +1080,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu ...@@ -1079,7 +1080,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Path of the file in the application sandbox. | | filePath | string | Yes | Path of the file in the application sandbox. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the file length.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the file length.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the content read. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the content read. |
**Example** **Example**
...@@ -1169,7 +1170,7 @@ Obtains information about a symbolic link. This API uses an asynchronous callbac ...@@ -1169,7 +1170,7 @@ Obtains information about a symbolic link. This API uses an asynchronous callbac
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | -------------------------------------- | | -------- | ---------------------------------- | ---- | -------------------------------------- |
| path | string | Yes | Path of the symbolic link in the application sandbox.| | path | string | Yes | Path of the symbolic link in the application sandbox.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback used to return the symbolic link information obtained. | | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the symbolic link information obtained. |
**Example** **Example**
...@@ -1215,7 +1216,7 @@ Obtains information about a symbolic link synchronously. ...@@ -1215,7 +1216,7 @@ Obtains information about a symbolic link synchronously.
rename(oldPath: string, newPath: string): Promise&lt;void&gt; rename(oldPath: string, newPath: string): Promise&lt;void&gt;
Renames a file. This API uses a promise to return the result. Renames a file or directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1248,7 +1249,7 @@ Renames a file. This API uses a promise to return the result. ...@@ -1248,7 +1249,7 @@ Renames a file. This API uses a promise to return the result.
rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void
Renames a file. This API uses an asynchronous callback to return the result. Renames a file or directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1278,7 +1279,7 @@ Renames a file. This API uses an asynchronous callback to return the result. ...@@ -1278,7 +1279,7 @@ Renames a file. This API uses an asynchronous callback to return the result.
renameSync(oldPath: string, newPath: string): void renameSync(oldPath: string, newPath: string): void
Synchronously renames a file. Renames a file or directory synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1366,7 +1367,7 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1366,7 +1367,7 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
fsyncSync(fd: number): void fsyncSync(fd: number): void
Flushes data of a file to disk in synchronous mode. Flushes data of a file to disk synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1454,7 +1455,7 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1454,7 +1455,7 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
fdatasyncSync(fd: number): void fdatasyncSync(fd: number): void
Synchronizes data in a file in synchronous mode. Synchronizes data in a file synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1560,6 +1561,239 @@ Synchronously creates a symbolic link based on a file path. ...@@ -1560,6 +1561,239 @@ Synchronously creates a symbolic link based on a file path.
fs.symlinkSync(srcFile, dstFile); fs.symlinkSync(srcFile, dstFile);
``` ```
## fs.listFile
listFile(path: string, options?: {
recursion?: boolean;
listNum?: number;
filter?: Filter;
}): Promise<string[]>;
Lists all files in a directory. This API uses a promise to return the result.<br>This API supports recursive listing of all files (including files in subdirectories) and file filtering.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.|
| options | Object | No | File filtering options.|
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string[]&gt; | Promise used to return the files names listed.|
**Example**
```js
let options = {
"recursion": false,
"listNum": 0,
"filter": {
"suffix": [".png", ".jpg", ".jpeg"],
"displayName": ["%abc", "efg%"],
"fileSizeOver": 1024,
"lastModifiedAfter": new Date().getTime(),
}
};
fs.listFile(pathDir, options).then((filenames) => {
console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) {
console.info("fileName: %s", filenames[i]);
}
}).catch((err) => {
console.info("list file failed with error message: " + err.message + ", error code: " + err.code);
});
```
## fs.listFile
listFile(path: string, options?: {
recursion?: boolean;
listNum?: number;
filter?: Filter;
}, callback: AsyncCallback<string[]>): void;
Lists all files in a directory. This API uses an asynchronous callback to return the result.<br>This API supports recursive listing of all files (including files in subdirectories) and file filtering.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.|
| options | Object | No | File filtering options.|
| callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. |
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Example**
```js
let options = {
"recursion": false,
"listNum": 0,
"filter": {
"suffix": [".png", ".jpg", ".jpeg"],
"displayName": ["%abc", "efg%"],
"fileSizeOver": 1024,
"lastModifiedAfter": new Date().getTime(),
}
};
fs.listFile(pathDir, options, (err, filenames) => {
if (err) {
console.info("list file failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) {
console.info("filename: %s", filenames[i]);
}
}
});
```
## listFileSync
listFileSync(path: string, options?: {
recursion?: boolean;
listNum?: number;
filter?: Filter;
}): string[];
Lists all files in a directory synchronously. This API supports recursive listing of all files (including files in subdirectories) and file filtering.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.|
| options | Object | No | File filtering options.|
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
| Type | Description |
| --------------------- | ---------- |
| string[] | File names listed.|
**Example**
```js
let options = {
"recursion": false,
"listNum": 0,
"filter": {
"suffix": [".png", ".jpg", ".jpeg"],
"displayName": ["%abc", "efg%"],
"fileSizeOver": 1024,
"lastModifiedAfter": new Date().getTime(),
}
};
let filenames = fs.listFileSync(pathDir, options);
console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) {
console.info("filename: %s", filenames[i]);
}
```
## moveFile
moveFile(src: string, dest: string, mode?: number): Promise<void>;
Moves a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example**
```js
fs.moveFile(srcPath, destPath, 0).then(() => {
console.info("move file succeed");
}).catch((err) => {
console.info("move file failed with error message: " + err.message + ", error code: " + err.code);
});
```
## moveFile
moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback<void>): void;
Moves a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. |
**Example**
```js
fs.moveFile(srcPath, destPath, 0, (err) => {
if (err) {
console.info("move file failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("move file succeed");
}
});
```
## moveFileSync
moveFile(src: string, dest: string, mode?: number): void;
Moves a file synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example**
```js
fs.moveFileSync(srcPath, destPath, 0);
console.info("move file succeed");
```
## fs.mkdtemp ## fs.mkdtemp
mkdtemp(prefix: string): Promise&lt;string&gt; mkdtemp(prefix: string): Promise&lt;string&gt;
...@@ -2354,6 +2588,104 @@ Represents a **File** object opened by **open()**. ...@@ -2354,6 +2588,104 @@ Represents a **File** object opened by **open()**.
| ---- | ------ | ---- | ---- | ------- | | ---- | ------ | ---- | ---- | ------- |
| fd | number | Yes | No | FD of the file.| | fd | number | Yes | No | FD of the file.|
### lock
lock(exclusive?: boolean): Promise<void>;
Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
file.lock(true).then(() => {
console.log("lock file successful");
}).catch((err) => {
console.info("lock file failed with error message: " + err.message + ", error code: " + err.code);
});
```
### lock
lock(exclusive?: boolean, callback: AsyncCallback<void>): void;
Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is locked. |
**Example**
```js
let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
file.lock(true, (err) => {
if (err) {
console.info("lock file failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.log("lock file successful");
}
});
```
### tryLock
tryLock(exclusive?: boolean): void;
Applies an exclusive lock or a shared lock on this file in non-blocking mode.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Example**
```js
let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
file.tryLock(true);
console.log("lock file successful");
```
### unlock
unlock(): void;
Unlocks this file synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Example**
```js
let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
file.tryLock(true);
file.unlock();
console.log("unlock file successful");
```
## OpenMode ## OpenMode
Defines the constants of the **mode** parameter used in **open()**. It species the mode for opening a file. Defines the constants of the **mode** parameter used in **open()**. It species the mode for opening a file.
...@@ -2372,3 +2704,18 @@ Defines the constants of the **mode** parameter used in **open()**. It species t ...@@ -2372,3 +2704,18 @@ Defines the constants of the **mode** parameter used in **open()**. It species t
| DIR | number | 0o200000 | If **path** does not point to a directory, throw an exception.| | DIR | number | 0o200000 | If **path** does not point to a directory, throw an exception.|
| NOFOLLOW | number | 0o400000 | If **path** points to a symbolic link, throw an exception.| | NOFOLLOW | number | 0o400000 | If **path** points to a symbolic link, throw an exception.|
| SYNC | number | 0o4010000 | Open the file in synchronous I/O mode.| | SYNC | number | 0o4010000 | Open the file in synchronous I/O mode.|
## Filter
**System capability**: SystemCapability.FileManagement.File.FileIO
Defines the file filtering configuration, which can be used by **listFile()**.
| Name | Type | Description |
| ----------- | --------------- | ------------------ |
| suffix | Array&lt;string&gt; | Locate files that fully match the specified file name extensions, which are of the OR relationship. |
| displayName | Array&lt;string&gt; | Locate files that fuzzy match the specified file names, which are of the OR relationship.|
| mimeType | Array&lt;string&gt; | Locate files that fully match the specified MIME types, which are of the OR relationship. |
| fileSizeOver | number | Locate files that are greater than or equal to the specified size. |
| lastModifiedAfter | number | Locate files whose last modification time is the same or later than the specified time. |
| excludeMedia | boolean | Whether to exclude the files already in **Media**. |
...@@ -36,14 +36,14 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -36,14 +36,14 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
```js ```js
let path = "/dev"; let path = "/dev";
statfs.getFreeSize(path).then((number) => { statvfs.getFreeSize(path).then((number) => {
console.info("getFreeSize promise successfully, Size: " + number); console.info("getFreeSize promise successfully, Size: " + number);
}).catch((err) => { }).catch((err) => {
console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code); console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
}); });
``` ```
## statfs.getFreeSize ## statvfs.getFreeSize
getFreeSize(path:string, callback:AsyncCallback&lt;number&gt;): void getFreeSize(path:string, callback:AsyncCallback&lt;number&gt;): void
...@@ -62,7 +62,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -62,7 +62,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
```js ```js
let path = "/dev"; let path = "/dev";
statfs.getFreeSize(path, (err, number) => { statvfs.getFreeSize(path, (err, number) => {
if (err) { if (err) {
console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code); console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
...@@ -71,7 +71,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -71,7 +71,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
}); });
``` ```
## statfs.getTotalSize ## statvfs.getTotalSize
getTotalSize(path: string): Promise&lt;number&gt; getTotalSize(path: string): Promise&lt;number&gt;
...@@ -95,14 +95,14 @@ Obtains the total number of bytes of the specified file system in asynchronous m ...@@ -95,14 +95,14 @@ Obtains the total number of bytes of the specified file system in asynchronous m
```js ```js
let path = "/dev"; let path = "/dev";
statfs.getTotalSize(path).then((number) => { statvfs.getTotalSize(path).then((number) => {
console.info("getTotalSize promise successfully, Size: " + number); console.info("getTotalSize promise successfully, Size: " + number);
}).catch((err) => { }).catch((err) => {
console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code); console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
}); });
``` ```
## statfs.getTotalSize ## statvfs.getTotalSize
getTotalSize(path: string, callback: AsyncCallback&lt;number&gt;): void getTotalSize(path: string, callback: AsyncCallback&lt;number&gt;): void
...@@ -121,7 +121,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m ...@@ -121,7 +121,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m
```js ```js
let path = "/dev"; let path = "/dev";
statfs.getTotalSize(path, (err, number) => { statvfs.getTotalSize(path, (err, number) => {
if (err) { if (err) {
console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code); console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
} else { } else {
......
# @ohos.volumeManager (Volume Management) # @ohos.file.volumeManager (Volument Management)
The volumeManager module provides APIs for volume and disk management, including obtaining volume information, mounting or unmounting volumes, partitioning disks, and formatting volumes. The volumeManager module provides APIs for volume and disk management, including obtaining volume information, mounting or unmounting volumes, partitioning disks, and formatting volumes.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 9. > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module are system APIs and cannot be called by third-party applications. > - The APIs provided by this module are system APIs.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import ## Modules to Import
```js ```js
import volumemanager from "@ohos.volumeManager"; import volumemanager from "@ohos.file.volumeManager";
``` ```
## volumemanager.getAllVolumes ## volumemanager.getAllVolumes
...@@ -65,7 +66,7 @@ Asynchronously obtains information about all available volumes. This API uses a ...@@ -65,7 +66,7 @@ Asynchronously obtains information about all available volumes. This API uses a
## volumemanager.mount ## volumemanager.mount
mount(volumeId: string): Promise&lt;boolean&gt; mount(volumeId: string): Promise&lt;void&gt;
Asynchronously mounts a volume. This API uses a promise to return the result. Asynchronously mounts a volume. This API uses a promise to return the result.
...@@ -83,7 +84,7 @@ Asynchronously mounts a volume. This API uses a promise to return the result. ...@@ -83,7 +84,7 @@ Asynchronously mounts a volume. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ---------------------- | ---------- | | ---------------------- | ---------- |
| Promise&lt;boolean&gt; | Promise used to return the execution result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -96,7 +97,7 @@ Asynchronously mounts a volume. This API uses a promise to return the result. ...@@ -96,7 +97,7 @@ Asynchronously mounts a volume. This API uses a promise to return the result.
## volumemanager.mount ## volumemanager.mount
mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void mount(volumeId: string, callback:AsyncCallback&lt;void&gt;):void
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result. Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
...@@ -109,7 +110,7 @@ Asynchronously obtains the available space of the specified volume. This API use ...@@ -109,7 +110,7 @@ Asynchronously obtains the available space of the specified volume. This API use
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. | | volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the execution result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example** **Example**
...@@ -122,7 +123,7 @@ Asynchronously obtains the available space of the specified volume. This API use ...@@ -122,7 +123,7 @@ Asynchronously obtains the available space of the specified volume. This API use
## volumemanager.unmount ## volumemanager.unmount
unmount(volumeId: string): Promise&lt;boolean&gt; unmount(volumeId: string): Promise&lt;void&gt;
Asynchronously unmounts a volume. This API uses a promise to return the result. Asynchronously unmounts a volume. This API uses a promise to return the result.
...@@ -140,7 +141,7 @@ Asynchronously unmounts a volume. This API uses a promise to return the result. ...@@ -140,7 +141,7 @@ Asynchronously unmounts a volume. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ---------------------- | ---------- | | ---------------------- | ---------- |
| Promise&lt;boolean&gt; | Promise used to return the execution result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -153,7 +154,7 @@ Asynchronously unmounts a volume. This API uses a promise to return the result. ...@@ -153,7 +154,7 @@ Asynchronously unmounts a volume. This API uses a promise to return the result.
## volumemanager.unmount ## volumemanager.unmount
unmount(volumeId: string, callback: AsyncCallback&lt;boolean&gt;): void unmount(volumeId: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously unmounts a volume. This API uses a callback to return the result. Asynchronously unmounts a volume. This API uses a callback to return the result.
...@@ -166,7 +167,7 @@ Asynchronously unmounts a volume. This API uses a callback to return the result. ...@@ -166,7 +167,7 @@ Asynchronously unmounts a volume. This API uses a callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. | | volumeId | string | Yes | Volume ID. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the execution result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example** **Example**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册