未验证 提交 a122dd14 编写于 作者: O openharmony_ci 提交者: Gitee

!15282 [翻译完成】I6E2N2 (14612+14511+15430+14259+14816+14124+14770)

Merge pull request !15282 from Annie_wang/PR14464
......@@ -218,8 +218,8 @@
- [@ohos.file.statvfs (File System Space Statistics)](js-apis-file-statvfs.md)
- [@ohos.filemanagement.userFileManager (User Data Management)](js-apis-userFileManager.md)
- [@ohos.multimedia.medialibrary (Media Library Management)](js-apis-medialibrary.md)
- [@ohos.storageStatistics (Application Storage Statistics)](js-apis-storage-statistics.md)
- [@ohos.volumeManager (Volume Management)](js-apis-volumemanager.md)
- [@ohos.file.storageStatistics (Application Storage Statistics)](js-apis-file-storage-statistics.md)
- [@ohos.file.volumeManager (Volume Management)](js-apis-file-volumemanager.md)
- Telephony Service
- [@ohos.contact (Contacts)](js-apis-contact.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
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) {
console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result));
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err) => {
let wantInfo = {
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));
});
})
}
try {
......@@ -252,18 +257,23 @@ Creates an app account implicitly based on the specified account owner and optio
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) {
console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result));
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err) => {
let wantInfo = {
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));
});
})
}
let options = {
......@@ -1346,7 +1356,7 @@ Authenticates an app account. This API uses an asynchronous callback to return t
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, authResult) {
console.log("resultCode: " + code);
......@@ -1354,10 +1364,17 @@ Authenticates an app account. This API uses an asynchronous callback to return t
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err) => {
console.log("startAbility err: " + JSON.stringify(err));
});
let wantInfo = {
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));
})
}
try {
......@@ -1402,7 +1419,7 @@ Authenticates an app account with customized options. This API uses an asynchron
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, authResult) {
console.log("resultCode: " + code);
......@@ -1410,10 +1427,17 @@ Authenticates an app account with customized options. This API uses an asynchron
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err) => {
console.log("startAbility err: " + JSON.stringify(err));
});
let wantInfo = {
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));
})
}
let options = {
......@@ -2706,7 +2730,7 @@ Adds an app account. This API uses an asynchronous callback to return the result
| 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<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Example**
......@@ -2724,6 +2748,7 @@ addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>)
Adds an app account name and additional information. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> 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
......@@ -2750,8 +2775,7 @@ addAccount(name: string, extraInfo?: string): Promise<void>
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).
**System capability**: SystemCapability.Account.AppAccount
......@@ -2803,7 +2827,7 @@ Adds an app account implicitly based on the specified owner. This API uses an as
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) {
console.log("resultCode: " + code);
......@@ -2811,10 +2835,17 @@ Adds an app account implicitly based on the specified owner. This API uses an as
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err)=>{
let wantInfo = {
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));
});
})
}
appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, {
......@@ -2839,7 +2870,7 @@ Deletes an app account. This API uses an asynchronous callback to return the res
| 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.|
**Example**
......@@ -2866,7 +2897,7 @@ Deletes an app account. This API uses a promise to return the result.
| 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**
......@@ -3751,18 +3782,23 @@ Authenticates an app account with customized options. This API uses an asynchron
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
function onResultCallback(code, result) {
console.log("resultCode: " + code);
console.log("result: " + JSON.stringify(result));
}
function onRequestRedirectedCallback(request) {
let abilityStartSetting = {want: request};
featureAbility.startAbility(abilityStartSetting, (err)=>{
console.log("startAbility err: " + JSON.stringify(err));
});
let wantInfo = {
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));
})
}
appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, {
......@@ -4521,10 +4557,13 @@ Enumerates the constants.
| KEY_REQUIRED_LABELS<sup>9+</sup> | "requiredLabels" | Required labels. |
| 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.
> **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
| Name | Value | Description |
......@@ -4760,7 +4799,7 @@ Creates an app account implicitly based on the specified account owner. This API
| 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.|
### addAccountImplicitly<sup>(deprecated)</sup>
......
......@@ -5,6 +5,7 @@ The **fs** module provides APIs for file operations, including basic file manage
> **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 APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import
......@@ -15,7 +16,7 @@ import fs from '@ohos.file.fs';
## 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**
......@@ -147,7 +148,7 @@ Checks whether a file exists. This API uses a promise to return the result.
| 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**
......@@ -554,7 +555,7 @@ Synchronously opens a file. File URIs are supported.
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Path of the file in the application sandbox or URI of the file. |
| mode | number | No | [Mode](#openmode) for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **OpenMode.READ_ONLY(0o0)**: Open the file in read-only mode.<br>- **OpenMode.WRITE_ONLY(0o1)**: Open the file in write-only mode.<br>- **OpenMode.READ_WRITE(0o2)**: Open the file in read/write mode.<br>You can also specify the following options, separated by a bitwise OR operator (&#124;). By default, no additional options are given.<br>- **OpenMode.CREATE(0o100)**: If the file does not exist, create it.<br>- **OpenMode.TRUNC(0o1000)**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **OpenMode.APPEND(0o2000)**: Open the file in append mode. New data will be added to the end of the file.<br>- **OpenMode.NONBLOCK(0o4000)**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **OpenMode.DIR(0o200000)**: If **path** does not point to a directory, throw an exception.<br>- **OpenMode.NOFOLLOW(0o400000)**: If **path** points to a symbolic link, throw an exception.<br>- **OpenMode.SYNC(0o4010000)**: Open the file in synchronous I/O mode.|
| mode | number | No | [Mode](#openmode) for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **OpenMode.READ_ONLY(0o0)**: Open the file in read-only mode.<br>- **OpenMode.WRITE_ONLY(0o1)**: Open the file in write-only mode.<br>- **OpenMode.READ_WRITE(0o2)**: Open the file in read/write mode.<br>You can also specify the following options, separated by a bitwise OR operator (&#124;). By default, no additional options are given.<br>- **OpenMode.CREATE(0o100)**: If the file does not exist, create it.<br>- **OpenMode.TRUNC(0o1000)**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **OpenMode.APPEND(0o2000)**: Open the file in append mode. New data will be added to the end of the file.<br>- **OpenMode.NONBLOCK(0o4000)**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **OpenMode.DIR(0o200000)**: If **path** does not point to a directory, throw an exception.<br>- **OpenMode.NOFOLLOW(0o400000)**: If **path** points to a symbolic link, throw an exception.<br>- **OpenMode.SYNC(0o4010000)**: Open the file in synchronous I/O mode.|
**Return value**
......@@ -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. |
| 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**
......@@ -1169,7 +1170,7 @@ Obtains information about a symbolic link. This API uses an asynchronous callbac
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | -------------------------------------- |
| 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**
......@@ -1215,7 +1216,7 @@ Obtains information about a symbolic link synchronously.
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
......@@ -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
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
......@@ -1278,7 +1279,7 @@ Renames a file. This API uses an asynchronous callback to return the result.
renameSync(oldPath: string, newPath: string): void
Synchronously renames a file.
Renames a file or directory synchronously.
**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
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
......@@ -1454,7 +1455,7 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
fdatasyncSync(fd: number): void
Synchronizes data in a file in synchronous mode.
Synchronizes data in a file synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1560,6 +1561,239 @@ Synchronously creates a symbolic link based on a file path.
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
mkdtemp(prefix: string): Promise&lt;string&gt;
......@@ -2354,6 +2588,104 @@ Represents a **File** object opened by **open()**.
| ---- | ------ | ---- | ---- | ------- |
| 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
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
| 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.|
| 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
```js
let path = "/dev";
statfs.getFreeSize(path).then((number) => {
statvfs.getFreeSize(path).then((number) => {
console.info("getFreeSize promise successfully, Size: " + number);
}).catch((err) => {
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
......@@ -62,7 +62,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
```js
let path = "/dev";
statfs.getFreeSize(path, (err, number) => {
statvfs.getFreeSize(path, (err, number) => {
if (err) {
console.info("getFreeSize failed with error message: " + err.message + ", error code: " + err.code);
} else {
......@@ -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;
......@@ -95,14 +95,14 @@ Obtains the total number of bytes of the specified file system in asynchronous m
```js
let path = "/dev";
statfs.getTotalSize(path).then((number) => {
statvfs.getTotalSize(path).then((number) => {
console.info("getTotalSize promise successfully, Size: " + number);
}).catch((err) => {
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
......@@ -121,7 +121,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m
```js
let path = "/dev";
statfs.getTotalSize(path, (err, number) => {
statvfs.getTotalSize(path, (err, number) => {
if (err) {
console.info("getTotalSize with error message: " + err.message + ", error code: " + err.code);
} else {
......
# @ohos.storageStatistics (Application Storage Statistics)
# @ohos.file.storageStatistics (Application Storage Statistics)
The **storageStatistics** module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.
> **NOTE**
>
> 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.
> - 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.
> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Modules to Import
```js
import storageStatistics from "@ohos.storageStatistics";
import storageStatistics from "@ohos.file.storageStatistics";
```
## storageStatistics.getTotalSizeOfVolume
getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
Asynchronously obtains the total size of the specified volume. This API uses a promise to return the result.
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
......@@ -36,7 +36,7 @@ This is a system API and cannot be called by third-party applications.
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;number&gt; | Promise used to return the total size of the volume.|
| Promise&lt;number&gt; | Promise used to return the total volume size obtained.|
**Example**
......@@ -53,14 +53,14 @@ This is a system API and cannot be called by third-party applications.
getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback&lt;number&gt;): void
Asynchronously obtains the total size of the specified volume. This API uses a callback to return the result.
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
......@@ -68,7 +68,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| volumeUuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total size of the volume.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total volume size obtained.|
**Example**
......@@ -84,14 +84,14 @@ This is a system API and cannot be called by third-party applications.
getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
Asynchronously obtains the available space of the specified volume. This API uses a promise to return the result.
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
......@@ -104,7 +104,7 @@ This is a system API and cannot be called by third-party applications.
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the available space of the volume.|
| Promise&lt;number&gt; | Promise used to return the available volume space obtained.|
**Example**
......@@ -122,14 +122,14 @@ This is a system API and cannot be called by third-party applications.
getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback&lt;number&gt;): void
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
......@@ -137,7 +137,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ---------------------------- |
| volumeUuid | string | Yes | UUID of the volume. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available space of the volume.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available volume space obtained.|
**Example**
......@@ -153,14 +153,14 @@ This is a system API and cannot be called by third-party applications.
getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
Asynchronously obtains space information of an application. This API uses a promise to return the result.
Obtains the space (in bytes) of an application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
......@@ -173,7 +173,7 @@ This is a system API and cannot be called by third-party applications.
| Type | Description |
| ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the space information obtained.|
| Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application space obtained.|
**Example**
......@@ -190,14 +190,14 @@ This is a system API and cannot be called by third-party applications.
getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void
Asynchronously obtains space information of an application. This API uses a callback to return the result.
Obtains the space (in bytes) of an application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
......@@ -205,7 +205,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | Yes | Bundle name of the application.|
| callback | AsyncCallback&lt;[Bundlestats](#bundlestats9)&gt; | Yes | Callback invoked to return the space information obtained.|
| callback | AsyncCallback&lt;[Bundlestats](#bundlestats9)&gt; | Yes | Callback invoked to return the application space obtained.|
**Example**
......@@ -221,7 +221,7 @@ This is a system API and cannot be called by third-party applications.
getCurrentBundleStats(): Promise&lt;BundleStats&gt;
Asynchronously obtains space information of the current third-party application. This API uses a promise to return the result.
Obtains the space (in bytes) of this third-party application. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
......@@ -229,7 +229,7 @@ Asynchronously obtains space information of the current third-party application.
| Type | Description |
| ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the space information obtained. |
| Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application space obtained. |
**Example**
......@@ -242,7 +242,7 @@ Asynchronously obtains space information of the current third-party application.
getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
Asynchronously obtains space information of the current third-party application. This API uses a callback to return the result.
Obtains the space (in bytes) of this third-party application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
......@@ -250,7 +250,7 @@ Asynchronously obtains space information of the current third-party application.
| Name | Type | Mandatory | Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt; | Yes | Callback invoked to return the space information obtained. |
| callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt; | Yes | Callback invoked to return the application space obtained. |
**Example**
......@@ -268,34 +268,33 @@ Asynchronously obtains space information of the current third-party application.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| --------- | ------ | --- | ---- | -------------- |
| appSize | number | Yes| No| Size of the application. |
| cacheSize | number | Yes| No| Cache size of the application. |
| dataSize | number | Yes| No| Total data size of the application.|
| appSize | number | Yes| No| Size of the application, in bytes. |
| cacheSize | number | Yes| No| Cache size of the application, in bytes. |
| dataSize | number | Yes| No| Total data size of the application, in bytes.|
## storageStatistics.getTotalSize<sup>9+</sup>
getTotalSize(): Promise&lt;number&gt;
Obtains the total space of the built-in memory card. This API uses a promise to return the result.
Obtains the total size (in bytes) of the built-in storage. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Return value**
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the total space of the built-in memory card. |
| Promise&lt;number&gt; | Promise used to return the built-in storage size obtained. |
**Example**
......@@ -308,21 +307,21 @@ This is a system API and cannot be called by third-party applications.
getTotalSize(callback: AsyncCallback&lt;number&gt;): void
Obtains the total space of the built-in memory card. This API uses a callback to return the result.
Obtains the total size (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the total space of the built-in memory card.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the built-in storage size obtained.|
**Example**
......@@ -338,21 +337,21 @@ This is a system API and cannot be called by third-party applications.
getFreeSize(): Promise&lt;number&gt;
Obtains the available space of the built-in memory card. This API uses a promise to return the result.
Obtains the available space (in bytes) of the built-in storage. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Return value**
| Type | Description |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the available space of the built-in memory card.|
| Promise&lt;number&gt; | Promise used to return the available space of the built-in storage obtained.|
**Example**
......@@ -366,21 +365,21 @@ This is a system API and cannot be called by third-party applications.
getFreeSize(callback: AsyncCallback&lt;number&gt;): void
Obtains the available space of the built-in memory card. This API uses a callback to return the result.
Obtains the available space (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available space of the built-in memory card.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the available space of the built-in storage obtained.|
**Example**
......@@ -395,21 +394,21 @@ This is a system API and cannot be called by third-party applications.
getSystemSize(): Promise&lt;number&gt;
Asynchronously obtains the system space. This API uses a promise to return the result.
Obtains the system data space, in bytes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;number&gt; | Promise used to return the system space obtained.|
| Promise&lt;number&gt; | Promise used to return the system data space obtained.|
**Example**
......@@ -425,21 +424,21 @@ This is a system API and cannot be called by third-party applications.
getSystemSize(callback: AsyncCallback&lt;number&gt;): void
Asynchronously obtains the system space. This API uses a callback to return the result.
Obtains the system data space, in bytes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the system space obtained.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the system data space obtained.|
**Example**
......@@ -452,23 +451,79 @@ This is a system API and cannot be called by third-party applications.
## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: number): Promise&lt;StorageStats&gt;
getUserStorageStats(): Promise&lt;StorageStats&gt;
Obtains the storage statistics (in bytes) of this user. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the information obtained.|
**Example**
```js
storageStatistics.getUserStorageStats().then(function(StorageStats){
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}).catch(function(err){
console.info("getUserStorageStats failed with error:"+ err);
});
```
## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(callback: AsyncCallback&lt;StorageStats&gt;): void
Obtains the storage statistics (in bytes) of this user. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes | Callback invoked to return the information obtained.|
**Example**
```js
storageStatistics.getUserStorageStats(function(error, StorageStats){
// Do something.
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
});
```
getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
Asynchronously obtains the space occupied by each type of user data. This API uses a promise to return the result.
Obtains the storage statistics (in bytes) of the specified user. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description|
| ---------- | ------ | ---- | ---- |
| userId | number | No | User ID.<br>Value:<br>-&nbsp; Set this parameter to the ID of the user to be queried.<br>-&nbsp; If no value is specified, information about the current user is queried.|
| userId | number | Yes | User ID.|
**Return value**
......@@ -479,7 +534,7 @@ This is a system API and cannot be called by third-party applications.
**Example**
```js
let userId = 1;
let userId = 100;
storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}).catch(function(err){
......@@ -489,29 +544,29 @@ This is a system API and cannot be called by third-party applications.
## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: number, callback: AsyncCallback&lt;StorageStats&gt;): void
getUserStorageStats(userId: number, callback: AsyncCallback&lt;StorageStats&gt;): void
Asynchronously obtains the space occupied by each type of user data. This API uses a callback to return the result.
Obtains the storage statistics (in bytes) of the specified user. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| userId | number | No | User ID.<br>Value:<br>-&nbsp; Set this parameter to the ID of the user to be queried.<br>-&nbsp; If no value is specified, information about the current user is queried. |
| userId | number | Yes | User ID.|
| callback | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes | Callback invoked to return the information obtained.|
**Example**
```js
let userId = 1;
let userId = 100;
storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
// Do something.
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
......@@ -526,13 +581,13 @@ This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
This is a system API.
| Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ----- | -------------- |
| total | number | Yes| No| Total space of the built-in memory card. |
| audio | number |Yes| No| Space occupied by audio data. |
| video | number | Yes| No| Space occupied by video data.|
| image | number | Yes| No| Space occupied by image data. |
| file | number | Yes| No| Space occupied by files. |
| app | number | Yes| No| Space occupied by application data.|
| total | number | Yes| No| Total size of the built-in storage, in bytes. |
| audio | number |Yes| No| Space occupied by audio data, in bytes. |
| video | number | Yes| No| Space occupied by video data, in bytes.|
| image | number | Yes| No| Space occupied by image data, in bytes. |
| file | number | Yes| No| Space occupied by files, in bytes. |
| app | number | Yes| No| Space occupied by application data, in bytes.|
# @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.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 9.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
> - 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 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
```js
import volumemanager from "@ohos.volumeManager";
import volumemanager from "@ohos.file.volumeManager";
```
## volumemanager.getAllVolumes
......@@ -65,7 +66,7 @@ Asynchronously obtains information about all available volumes. This API uses a
## 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.
......@@ -83,7 +84,7 @@ Asynchronously mounts a volume. This API uses a promise to return the result.
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;boolean&gt; | Promise used to return the execution result.|
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......@@ -96,7 +97,7 @@ Asynchronously mounts a volume. This API uses a promise to return the result.
## 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.
......@@ -109,7 +110,7 @@ Asynchronously obtains the available space of the specified volume. This API use
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- |
| 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**
......@@ -122,7 +123,7 @@ Asynchronously obtains the available space of the specified volume. This API use
## 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.
......@@ -140,7 +141,7 @@ Asynchronously unmounts a volume. This API uses a promise to return the result.
| Type | Description |
| ---------------------- | ---------- |
| Promise&lt;boolean&gt; | Promise used to return the execution result.|
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
......@@ -153,7 +154,7 @@ Asynchronously unmounts a volume. This API uses a promise to return the result.
## 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.
......@@ -166,7 +167,7 @@ Asynchronously unmounts a volume. This API uses a callback to return the result.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- |
| 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**
......
......@@ -25,9 +25,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.|
| Type| Description|
| --- | -- |
| Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.|
**Example**
......@@ -55,9 +55,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.|
**Example**
......@@ -89,16 +89,16 @@ Synchronously creates a **Helper** object to connect to the specified wants. The
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| wants | Array&lt;Want&gt; | Yes| Wants to connect.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| wants | Array&lt;Want&gt; | Yes| Wants to connect.|
**Return value**
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
**Example**
......@@ -136,26 +136,26 @@ Synchronously creates a **Helper** object to connect to all file management serv
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
**Return value**
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| Type| Description|
| --- | -- |
| FileAccessHelper | **Helper** object created.|
**Example**
```js
createFileAccessHelper() {
let fileAccesssHelperAllServer = null;
let fileAccessHelperAllServer = null;
// Create a Helper object to interact with all file management services configured with fileAccess in the system.
try {
// this.context is passed by EntryAbility.
fileAccesssHelperAllServer = fileAccess.createFileAccessHelper(this.context);
if (!fileAccesssHelperAllServer)
fileAccessHelperAllServer = fileAccess.createFileAccessHelper(this.context);
if (!fileAccessHelperAllServer)
console.error("createFileAccessHelper interface returns an undefined object");
} catch (error) {
console.error("createFileAccessHelper failed, errCode:" + error.code + ", errMessage:" + error.message);
......@@ -175,9 +175,9 @@ Obtains information about the device root nodes of the file management service t
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.|
| Type| Description|
| --- | -- |
| Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.|
**Example**
......@@ -210,7 +210,9 @@ Obtains information about the device root nodes of the file management service t
getRoots(callback:AsyncCallback&lt;RootIterator&gt;) : void;
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result. The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext).
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result.
The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -218,9 +220,9 @@ Obtains information about the device root nodes of the file management service t
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.|
**Example**
......@@ -253,7 +255,7 @@ Obtains information about the device root nodes of the file management service t
listFile(filter?: Filter) : FileIterator
Synchronously obtains the **FileIterator** object of the first-level files (file folder) matching the conditions of the filter from the device root node. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
Synchronously obtains the **FileIterator** object of the first-level files (file directory) matching the conditions of the filter from the device root node. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -261,16 +263,16 @@ Synchronously obtains the **FileIterator** object of the first-level files (file
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -312,15 +314,15 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -354,7 +356,7 @@ Recursively obtains the **FileIterator** object of the files matching the condit
listFile(filter?: Filter) : FileIterator
Synchronously obtains the **FileIterator** object of the next-level files (file folders) matching the conditions of the filter from a directory. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
Synchronously obtains the **FileIterator** object of the next-level files (file directories) matching the conditions of the filter from a directory. The **FileIterator** object then returns [FileInfo](#fileinfo) by using [next()](#fileiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -362,15 +364,15 @@ Synchronously obtains the **FileIterator** object of the next-level files (file
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -412,16 +414,16 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
| Name| Type| Mandatory| Description|
| --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. |
**Return value**
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
| Type| Description|
| --- | -- |
| FileIterator | **FileIterator** object obtained.|
**Example**
......@@ -463,10 +465,10 @@ Creates a file in a directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
**Return value**
......@@ -508,11 +510,11 @@ Creates a file in a directory. This API uses an asynchronous callback to return
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.|
**Example**
......@@ -540,7 +542,7 @@ Creates a file in a directory. This API uses an asynchronous callback to return
mkDir(parentUri: string, displayName: string) : Promise&lt;string&gt;
Creates a folder in a directory. This API uses a promise to return the result.
Creates a directory in a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -548,16 +550,16 @@ Creates a folder in a directory. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the folder to create.|
| displayName | string | Yes| Name of the folder to create.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the folder created.|
| Promise&lt;string&gt; | Promise used to return the URI of the directory created.|
**Example**
......@@ -585,7 +587,7 @@ Creates a folder in a directory. This API uses a promise to return the result.
mkDir(parentUri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void;
Creates a folder in a directory. This API uses an asynchronous callback to return the result.
Creates a directory in a directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -593,11 +595,11 @@ Creates a folder in a directory. This API uses an asynchronous callback to retur
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the folder to create.|
| displayName | string | Yes| Name of the folder to create.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the folder created.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the directory to create.|
| displayName | string | Yes| Name of the directory to create.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the directory created.|
**Example**
......@@ -633,10 +635,10 @@ Opens a file. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
**Return value**
......@@ -671,11 +673,11 @@ Opens a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the file descriptor of the file opened.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the file descriptor of the file opened.|
**Example**
......@@ -702,7 +704,7 @@ Opens a file. This API uses an asynchronous callback to return the result.
delete(uri: string) : Promise&lt;number&gt;
Deletes a file or folder. This API uses a promise to return the result.
Deletes a file or directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -710,9 +712,9 @@ Deletes a file or folder. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to delete.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
**Return value**
......@@ -741,7 +743,7 @@ Deletes a file or folder. This API uses a promise to return the result.
delete(uri: string, callback: AsyncCallback&lt;number&gt;) : void;
Deletes a file or folder. This API uses an asynchronous callback to return the result.
Deletes a file or directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -749,10 +751,10 @@ Deletes a file or folder. This API uses an asynchronous callback to return the r
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to delete.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to delete.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.|
**Example**
......@@ -779,7 +781,7 @@ Deletes a file or folder. This API uses an asynchronous callback to return the r
move(sourceFile: string, destFile: string) : Promise&lt;string&gt;
Moves a file or folder. This API uses a promise to return the result.
Moves a file or directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -787,22 +789,22 @@ Moves a file or folder. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or folder to move.|
| destFile | string | Yes| URI of the folder to which the file or folder will be moved.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
**Return value**
| Type| Description|
| ----- | ------ |
| Promise&lt;string&gt; | Promise used to return the URI of the file or folder in the destination directory.|
| Promise&lt;string&gt; | Promise used to return the URI of the file or directory in the destination directory.|
**Example**
```js
// The media library URI is used as an example.
//In the sample code, sourceFile destFile indicates the file or folder in the Download directory. The URI is the URI in fileInfo.
//In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained.
let sourceFile = "datashare:///media/file/102";
let destFile = "datashare:///media/file/101";
......@@ -819,7 +821,7 @@ Moves a file or folder. This API uses a promise to return the result.
move(sourceFile: string, destFile: string, callback: AsyncCallback&lt;string&gt;) : void;
Moves a file or folder. This API uses an asynchronous callback to return the result.
Moves a file or directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -827,17 +829,17 @@ Moves a file or folder. This API uses an asynchronous callback to return the res
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or folder to move.|
| destFile | string | Yes| URI of the folder to which the file or folder will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or folder in the destination directory.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or directory to move.|
| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or directory in the destination directory.|
**Example**
```js
// The media library URI is used as an example.
//In the sample code, sourceFile destFile indicates the file or folder in the Download directory. The URI is the URI in fileInfo.
//In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo.
// You can use the URI obtained.
let sourceFile = "datashare:///media/file/102";
let destFile = "datashare:///media/file/101";
......@@ -859,7 +861,7 @@ Moves a file or folder. This API uses an asynchronous callback to return the res
rename(uri: string, displayName: string) : Promise&lt;string&gt;
Renames a file or folder. 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.UserFileService
......@@ -867,16 +869,16 @@ Renames a file or folder. This API uses a promise to return the result.
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to rename.|
| displayName | string | Yes| New name of the file or folder, which can contain the file name extension.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
**Return value**
| Type| Description|
| --- | -- |
| Promise&lt;string&gt; | Promise used to return the URI of the renamed file or folder.|
| Promise&lt;string&gt; | Promise used to return the URI of the renamed file or directory.|
**Example**
......@@ -898,7 +900,7 @@ Renames a file or folder. This API uses a promise to return the result.
rename(uri: string, displayName: string, callback: AsyncCallback&lt;string&gt;) : void;
Renames a file or folder. 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.UserFileService
......@@ -906,11 +908,11 @@ Renames a file or folder. This API uses an asynchronous callback to return the r
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to rename.|
| displayName | string | Yes| New name of the file or folder, which can contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or folder.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| uri | string | Yes| URI of the file or directory to rename.|
| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or directory.|
**Example**
......@@ -937,7 +939,7 @@ Renames a file or folder. This API uses an asynchronous callback to return the r
access(sourceFileUri: string) : Promise&lt;boolean&gt;
Checks whether a file or folder exists. This API uses a promise to return the result.
Checks whether a file or directory exists. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -945,9 +947,9 @@ Checks whether a file or folder exists. This API uses a promise to return the re
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or folder.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
**Return value**
......@@ -978,7 +980,7 @@ Checks whether a file or folder exists. This API uses a promise to return the re
access(sourceFileUri: string, callback: AsyncCallback&lt;boolean&gt;) : void;
Checks whether a file or folder exists. This API uses an asynchronous callback to return the result.
Checks whether a file or directory exists. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -986,10 +988,10 @@ Checks whether a file or folder exists. This API uses an asynchronous callback t
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or folder.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or directory.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.|
**Example**
......@@ -1029,13 +1031,13 @@ Obtains the next-level device root directory. **RootIterator** is an iterator ob
| Type| Description|
| --- | -- |
| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the folder until **done** returns **true**. The **value** field contains the root directory information.|
| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the directory until **done** returns **true**. The **value** field contains the root directory information.|
## FileIterator.next
next( ) : { value: FileInfo, done: boolean }
Obtains the information about the next-level file or folder. **FileIterator** is an iterator object of a folder.
Obtains the information about the next-level file or directory. **FileIterator** is an iterator object of a directory.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -1045,7 +1047,7 @@ Obtains the information about the next-level file or folder. **FileIterator** is
| Type| Description|
| --- | -- |
| {value: FileInfo, done: boolean} | File or folder information obtained. This API traverses the specified folder until **done** returns **true**. The **value** field contains the file or folder information obtained.|
| {value: FileInfo, done: boolean} | File or directory information obtained. This API traverses the specified directory until **done** returns **true**. The **value** field contains the file or directory information obtained.|
## RootInfo
......@@ -1066,7 +1068,7 @@ Represents the root attribute information and interface capabilities of a device
## FileInfo
Represents the file or folder attribute information and interface capabilities.
Represents the file or directory attribute information and interface capabilities.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -1076,12 +1078,12 @@ Represents the file or folder attribute information and interface capabilities.
| Name| Type | Readable| Writable| Description |
| ------ | ------ | -------- | ------ | -------- |
| uri | string | Yes| No| URI of the file or folder.|
| fileName | string | Yes| No| Name of a file or folder.|
| mode | number | Yes| No| Permissions on the file or folder.|
| size | number | Yes| No| Size of the file or folder.|
| mtime | number | Yes| No| Time when the file or folder was last modified.|
| mimeType | string | Yes| No| MIME type of the file or folder.|
| uri | string | Yes| No| URI of the file or directory.|
| fileName | string | Yes| No| Name of a file or directory.|
| mode | number | Yes| No| Permissions on the file or directory.|
| size | number | Yes| No| Size of the file or directory.|
| mtime | number | Yes| No| Time when the file or directory was last modified.|
| mimeType | string | Yes| No| MIME type of the file or directory.|
## OPENFLAGS
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册