| 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.|
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).
| name | string | Yes | Name of the target app account. |
| name | string | Yes | Name of the app account to delete. |
| 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**
...
...
@@ -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
| 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).
@@ -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.
| 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<string> | Yes | Callback used to return the content read. |
| callback | AsyncCallback<string> | 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
@@ -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.
| 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<string[]> | Promise used to return the files names listed.|
**Example**
```js
letoptions={
"recursion":false,
"listNum":0,
"filter":{
"suffix":[".png",".jpg",".jpeg"],
"displayName":["%abc","efg%"],
"fileSizeOver":1024,
"lastModifiedAfter":newDate().getTime(),
}
};
fs.listFile(pathDir,options).then((filenames)=>{
console.info("listFile succeed");
for(leti=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.
| 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
letoptions={
"recursion":false,
"listNum":0,
"filter":{
"suffix":[".png",".jpg",".jpeg"],
"displayName":["%abc","efg%"],
"fileSizeOver":1024,
"lastModifiedAfter":newDate().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(leti=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.
| 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.|
| 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);
| 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<void> | 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);
| 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<string>
...
...
@@ -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.
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).