You need to sign in or sign up before continuing.
未验证 提交 283b8557 编写于 作者: O openharmony_ci 提交者: Gitee

!15641 bugfix fs 示例代码修改

Merge pull request !15641 from zhuhongtao666/fsdoc
...@@ -474,7 +474,7 @@ mkdirSync(path: string): void ...@@ -474,7 +474,7 @@ mkdirSync(path: string): void
**示例:** **示例:**
```js ```js
let dirPath = path + '/testDir'; let dirPath = pathDir + '/testDir';
fs.mkdirSync(dirPath); fs.mkdirSync(dirPath);
``` ```
...@@ -1606,7 +1606,7 @@ listFile(path: string, options?: { ...@@ -1606,7 +1606,7 @@ listFile(path: string, options?: {
}; };
fs.listFile(pathDir, options).then((filenames) => { fs.listFile(pathDir, options).then((filenames) => {
console.info("listFile succeed"); console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) { for (let i = 0; i < filenames.length; i++) {
console.info("fileName: %s", filenames[i]); console.info("fileName: %s", filenames[i]);
} }
}).catch((err) => { }).catch((err) => {
...@@ -1657,7 +1657,7 @@ listFile(path: string, options?: { ...@@ -1657,7 +1657,7 @@ listFile(path: string, options?: {
console.info("list file failed with error message: " + err.message + ", error code: " + err.code); console.info("list file failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
console.info("listFile succeed"); console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) { for (let i = 0; i < filenames.length; i++) {
console.info("filename: %s", filenames[i]); console.info("filename: %s", filenames[i]);
} }
} }
...@@ -1710,7 +1710,7 @@ listFileSync(path: string, options?: { ...@@ -1710,7 +1710,7 @@ listFileSync(path: string, options?: {
}; };
let filenames = fs.listFileSync(pathDir, options); let filenames = fs.listFileSync(pathDir, options);
console.info("listFile succeed"); console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) { for (let i = 0; i < filenames.length; i++) {
console.info("filename: %s", filenames[i]); console.info("filename: %s", filenames[i]);
} }
``` ```
...@@ -1733,6 +1733,8 @@ moveFile(src: string, dest: string, mode?: number): Promise<void>; ...@@ -1733,6 +1733,8 @@ moveFile(src: string, dest: string, mode?: number): Promise<void>;
**示例:** **示例:**
```js ```js
let srcPath = pathDir + '/source.txt';
let destPath = pathDir + '/dest.txt';
fs.moveFile(srcPath, destPath, 0).then(() => { fs.moveFile(srcPath, destPath, 0).then(() => {
console.info("move file succeed"); console.info("move file succeed");
}).catch((err) => { }).catch((err) => {
...@@ -1760,6 +1762,8 @@ moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback<void> ...@@ -1760,6 +1762,8 @@ moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback<void>
**示例:** **示例:**
```js ```js
let srcPath = pathDir + '/source.txt';
let destPath = pathDir + '/dest.txt';
fs.moveFile(srcPath, destPath, 0, (err) => { fs.moveFile(srcPath, destPath, 0, (err) => {
if (err) { if (err) {
console.info("move file failed with error message: " + err.message + ", error code: " + err.code); console.info("move file failed with error message: " + err.message + ", error code: " + err.code);
...@@ -1788,6 +1792,8 @@ moveFile(src: string, dest: string, mode?: number): void; ...@@ -1788,6 +1792,8 @@ moveFile(src: string, dest: string, mode?: number): void;
**示例:** **示例:**
```js ```js
let srcPath = pathDir + '/source.txt';
let destPath = pathDir + '/dest.txt';
fs.moveFileSync(srcPath, destPath, 0); fs.moveFileSync(srcPath, destPath, 0);
console.info("move file succeed"); console.info("move file succeed");
``` ```
......
...@@ -66,7 +66,8 @@ setSecurityLabel(path:string, type:DataLevel):Promise&lt;void&gt; ...@@ -66,7 +66,8 @@ setSecurityLabel(path:string, type:DataLevel):Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
securityLabel.setSecurityLabel(path, "s0").then(() => { let filePath = pathDir + '/test.txt';
securityLabel.setSecurityLabel(filePath, "s0").then(() => {
console.info("setSecurityLabel successfully"); console.info("setSecurityLabel successfully");
}).catch((err) => { }).catch((err) => {
console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code);
...@@ -92,7 +93,8 @@ setSecurityLabel(path:string, type:DataLevel, callback: AsyncCallback&lt;void&gt ...@@ -92,7 +93,8 @@ setSecurityLabel(path:string, type:DataLevel, callback: AsyncCallback&lt;void&gt
**示例:** **示例:**
```js ```js
securityLabel.setSecurityLabel(path, "s0", (err) => { let filePath = pathDir + '/test.txt';
securityLabel.setSecurityLabel(filePath, "s0", (err) => {
if (err) { if (err) {
console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
...@@ -119,7 +121,8 @@ setSecurityLabelSync(path:string, type:DataLevel):void ...@@ -119,7 +121,8 @@ setSecurityLabelSync(path:string, type:DataLevel):void
**示例:** **示例:**
```js ```js
securityLabel.setSecurityLabelSync(path, "s0"); let filePath = pathDir + '/test.txt';
securityLabel.setSecurityLabelSync(filePath, "s0");
``` ```
## securityLabel.getSecurityLabel ## securityLabel.getSecurityLabel
...@@ -145,7 +148,8 @@ getSecurityLabel(path:string):Promise&lt;string&gt; ...@@ -145,7 +148,8 @@ getSecurityLabel(path:string):Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
securityLabel.getSecurityLabel(path).then((type) => { let filePath = pathDir + '/test.txt';
securityLabel.getSecurityLabel(filePath).then((type) => {
console.log("getSecurityLabel successfully, Label: " + type); console.log("getSecurityLabel successfully, Label: " + type);
}).catch((err) => { }).catch((err) => {
console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code);
...@@ -170,7 +174,8 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void ...@@ -170,7 +174,8 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
securityLabel.getSecurityLabel(path, (err, type) => { let filePath = pathDir + '/test.txt';
securityLabel.getSecurityLabel(filePath, (err, type) => {
if (err) { if (err) {
console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
...@@ -201,6 +206,7 @@ getSecurityLabelSync(path:string):string ...@@ -201,6 +206,7 @@ getSecurityLabelSync(path:string):string
**示例:** **示例:**
```js ```js
let type = securityLabel.getSecurityLabelSync(path); let filePath = pathDir + '/test.txt';
let type = securityLabel.getSecurityLabelSync(filePath);
console.log("getSecurityLabel successfully, Label: " + type); console.log("getSecurityLabel successfully, Label: " + type);
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册