| uriOrPath | string | Yes| URI or path. The following types of URIs are available:<br>- Application sandbox URI: **file://\<bundleName>/\<sandboxPath>**<br>- URI of the user's document: **file://docs/storage/Users/currentUser/\<publicPath>**<br>- URI of the user's media asset: **file://media/\<mediaType>/IMG_DATATIME_ID/\<displayName>**|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| src | string | Yes | Application sandbox path of the directory to copy.|
| src | string | Yes | Application sandbox path of the directory to copy.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| mode | number | No | Copy mode. The default value is **0**.<br>- **0**: Throw an exception if a file conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles)> format.<br>- **1**: Forcibly overwrite the files with the same name in the destination directory.<br>If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.|
| mode | number | No | Copy mode. The default value is **0**.<br>- **0**: Throw an exception if a file conflict occurs.<br>Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles10)> format.<br>- **1**: Forcibly overwrite the files with the same name in the destination directory. If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.|
**Return value**
**Return value**
...
@@ -494,7 +495,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -494,7 +495,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
| src | string | Yes | Application sandbox path of the directory to copy.|
| src | string | Yes | Application sandbox path of the directory to copy.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| mode | number | No | Copy mode. The default value is **0**.<br>- **0**: Throw an exception if a file conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles)> format.<br>- **1**: Forcibly overwrite the files with the same name in the destination directory.<br>If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.|
| mode | number | No | Copy mode. The default value is **0**.<br>- **0**: Throw an exception if a file conflict occurs.<br>Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles10)> format.<br>- **1**: Forcibly overwrite the files with the same name in the destination directory. If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.|
| callback | AsyncCallback<void> | Yes | Callback invoked immediately after the directory is copied. |
| callback | AsyncCallback<void, Array<[ConflictFiles](#conflictfiles10)>> | Yes | Callback invoked immediately after the directory is copied. |
**Error codes**
**Error codes**
...
@@ -533,6 +534,41 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -533,6 +534,41 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
});
});
```
```
## fs.dup<sup>10+</sup>
dup(fd: number): File
Opens a **File** object based on the specified FD.
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**. If **recursion** is **false**, the names of the files and folders that meet the specified conditions in the current directory are returned. If **recursion** is **true**, the relative paths (starting with /) of all files that meet the specified conditions in the directory are returned.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| 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.|
| 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.|
...
@@ -1873,7 +1910,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -1873,7 +1910,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
"listNum":0,
"listNum":0,
"filter":{
"filter":{
"suffix":[".png",".jpg",".jpeg"],
"suffix":[".png",".jpg",".jpeg"],
"displayName":["%abc","efg%"],
"displayName":["*abc","efg*"],
"fileSizeOver":1024,
"fileSizeOver":1024,
"lastModifiedAfter":newDate().getTime(),
"lastModifiedAfter":newDate().getTime(),
}
}
...
@@ -1911,7 +1948,7 @@ Lists all files in a folder. This API uses an asynchronous callback to return th
...
@@ -1911,7 +1948,7 @@ Lists all files in a folder. This API uses an asynchronous callback to return th
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**. If **recursion** is **false**, the names of the files and folders that meet the specified conditions in the current directory are returned. If **recursion** is **true**, the relative paths (starting with /) of all files that meet the specified conditions in the directory are returned.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| 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.|
| 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.|
...
@@ -1927,7 +1964,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -1927,7 +1964,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
"listNum":0,
"listNum":0,
"filter":{
"filter":{
"suffix":[".png",".jpg",".jpeg"],
"suffix":[".png",".jpg",".jpeg"],
"displayName":["%abc","efg%"],
"displayName":["*abc","efg*"],
"fileSizeOver":1024,
"fileSizeOver":1024,
"lastModifiedAfter":newDate().getTime(),
"lastModifiedAfter":newDate().getTime(),
}
}
...
@@ -1967,7 +2004,7 @@ Lists all files in a folder synchronously. This API supports recursive listing o
...
@@ -1967,7 +2004,7 @@ Lists all files in a folder synchronously. This API supports recursive listing o
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**. If **recursion** is **false**, the names of the files and folders that meet the specified conditions in the current directory are returned. If **recursion** is **true**, the relative paths (starting with /) of all files that meet the specified conditions in the directory are returned.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| 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.|
| 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.|
...
@@ -1989,7 +2026,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -1989,7 +2026,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
"listNum":0,
"listNum":0,
"filter":{
"filter":{
"suffix":[".png",".jpg",".jpeg"],
"suffix":[".png",".jpg",".jpeg"],
"displayName":["%abc","efg%"],
"displayName":["*abc","efg*"],
"fileSizeOver":1024,
"fileSizeOver":1024,
"lastModifiedAfter":newDate().getTime(),
"lastModifiedAfter":newDate().getTime(),
}
}
...
@@ -2015,7 +2052,7 @@ Moves a directory. This API uses a promise to return the result.
...
@@ -2015,7 +2052,7 @@ Moves a directory. This API uses a promise to return the result.
| src | string | Yes | Application sandbox path of the directory to move.|
| src | string | Yes | Application sandbox path of the directory to move.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| mode | number | No | Mode for moving the directory. The default value is **0**.<br>- **0**: Throw an exception if a directory conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory.<br>- **1**: Throw an exception if a file conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles)> format.<br>- **2**: Forcibly overwrite the conflicting files in the destination directory.<br>If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.<br>- **3**: Forcibly overwrite the conflicting directory.<br>Move the source directory to the destination directory and overwrite the conflicting directory completely. That is, if there is a directory with the same name in the destination directory, all the original files in that directory will not be retained.|
| mode | number | No | Mode for moving the directory. The default value is **0**.<br>- **0**: Throw an exception if a directory conflict occurs.<br>Throw an exception if there is a non-empty directory with the same name in the destination directory.<br>- **1**: Throw an exception if a file conflict occurs.<br>Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles10)> format.<br>- **2**: Forcibly overwrite the conflicting files in the destination directory. If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.<br>- **3**: Forcibly overwrite the conflicting directory.<br>Move the source directory to the destination directory and overwrite the conflicting directory completely. That is, if there is a directory with the same name in the destination directory, all the original files in that directory will not be retained.|
**Return value**
**Return value**
...
@@ -2049,7 +2086,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -2049,7 +2086,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
| src | string | Yes | Application sandbox path of the source directory.|
| src | string | Yes | Application sandbox path of the source directory.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| dest | string | Yes | Application sandbox path of the destination directory.|
| mode | number | No | Mode for moving the directory. The default value is **0**.<br>- **0**: Throw an exception if a directory conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory.<br>- **1**: Throw an exception if a file conflict occurs.<br> Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles)> format.<br>- **2**: Forcibly overwrite the conflicting files in the destination directory. If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.<br>- **3**: Forcibly overwrite the conflicting directory.<br>Move the source directory to the destination directory and overwrite the conflicting directory completely. That is, if there is a directory with the same name in the destination directory, all the original files in that directory will not be retained.|
| mode | number | No | Mode for moving the directory. The default value is **0**.<br>- **0**: Throw an exception if a directory conflict occurs.<br>Throw an exception if there is a directory with the same name in the destination directory.<br>- **1**: Throw an exception if a file conflict occurs.<br>Throw an exception if there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory. All the non-conflicting files in the source directory will be moved to the destination directory, and the non-conflicting files in the destination directory will be retained. The **data** attribute in the error returned provides information about the conflicting files in the Array\<[ConflictFiles](#conflictfiles10)> format.<br>- **2**: Forcibly overwrite the conflicting files in the destination directory. If there is a directory with the same name in the destination directory and files with the same name exist in the conflicting directory, all the files with the same name in the destination directory will be overwritten and the non-conflicting files will be retained.<br>- **3**: Forcibly overwrite the conflicting directory.<br>Move the source directory to the destination directory and overwrite the conflicting directory completely. That is, if there is a directory with the same name in the destination directory, all the original files in that directory will not be retained.|
| callback | AsyncCallback<void> | Yes | Callback invoked when the directory is moved. |
| callback | AsyncCallback<void, Array<[ConflictFiles](#conflictfiles10)>> | Yes | Callback invoked when the directory is moved. |
**Error codes**
**Error codes**
...
@@ -2288,7 +2325,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -2288,7 +2325,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to read the data. This parameter is optional. By default, data is read from the current position.<br>|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to read the data. This parameter is optional. By default, data is read from the current position.<br>|
**Return value**
**Return value**
...
@@ -3263,6 +3306,8 @@ Represents a **File** object opened by **open()**.
...
@@ -3263,6 +3306,8 @@ Represents a **File** object opened by **open()**.
| Name | Type | Readable | Writable | Description |
| Name | Type | Readable | Writable | Description |
| ---- | ------ | ---- | ---- | ------- |
| ---- | ------ | ---- | ---- | ------- |
| fd | number | Yes | No | FD of the file.|
| fd | number | Yes | No | FD of the file.|
| path<sup>10+</sup> | string | Yes | No | Path of the file.|
| name<sup>10+</sup> | string | Yes | No | Name of the file.|
### lock
### lock
...
@@ -3410,6 +3455,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -3410,6 +3455,7 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to read the data (it is determined by **filePointer** plus **offset**). This parameter is optional. By default, data is read from the **filePointer**.<br>|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to read the data (it is determined by **filePointer** plus **offset**). This parameter is optional. By default, data is read from the **filePointer**.<br>|
**Return value**
**Return value**
...
@@ -3649,10 +3706,12 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
...
@@ -3649,10 +3706,12 @@ For details about the error codes, see [Basic File IO Error Codes](../errorcodes
console.error('PhotoViewPicker failed with err: '+err);
leterr:BusinessError=errorasBusinessError;
console.error('PhotoViewPicker failed with err: '+JSON.stringify(err));
}
}
}
}
```
```
## DocumentViewPicker
## DocumentViewPicker
Provides APIs for selecting and saving non-media files, for example, documents in a variety of formats. Before using the APIs of **DocumentViewPicker**, you need to create a **DocumentViewPicker** instance.
Provides the **DocumentViewPicker** object for selecting and saving documents in different formats. Before using the APIs of **DocumentViewPicker**, you need to create a **DocumentViewPicker** instance.
| maxSelectNumber<sup>10+</sup> | number | No | Maximum number of files or directories that can be selected.<br>Value range: 1–500<br>Maximum value: **500** |
| defaultFilePathUri<sup>10+</sup> | string | No | Path of the file or directory to select.|
| fileSuffixFilters<sup>10+</sup> | Array<string> | No | File name extensions of the documents to select.|
## DocumentSaveOptions
## DocumentSaveOptions
Defines the options for saving documents.
Defines the options for saving documents.
...
@@ -753,7 +782,9 @@ Defines the options for saving documents.
...
@@ -753,7 +782,9 @@ Defines the options for saving documents.
| newFileNames? | Array<string> | No | Names of the documents to save. If this parameter is not specified, the user needs to enter the document names. |
| newFileNames | Array<string> | No | Names of the documents to save. If this parameter is not specified, the user needs to enter the document names. |
| defaultFilePathUri<sup>10+</sup> | string | No | Path of the file or directory to save.|
| fileSuffixChoices<sup>10+</sup> | Array<string> | No | File name extensions of the documents to save.|
## AudioSelectOptions
## AudioSelectOptions
...
@@ -769,4 +800,4 @@ Defines the options for saving audio files.
...
@@ -769,4 +800,4 @@ Defines the options for saving audio files.
| newFileNames? | Array<string> | No | Name of the audio files to save. If this parameter is not specified, the user needs to enter the file names.|
| newFileNames | Array<string> | No | Name of the audio files to save. If this parameter is not specified, the user needs to enter the file names.|