#鸿蒙学习大百科#如何创建一个多级的目录?

如何创建一个多级的目录?

HarmonyOS
2024-10-16 08:46:12
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
耗子煨汁r
import { common } from '@kit.AbilityKit';
import fs from '@ohos.file.fs';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  private context = getContext(this) as common.UIAbilityContext;
  build() {
    Row() {
      Column() {
        Text("Hello")
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let applicationContext = this.context.getApplicationContext();
            let cacheDir = applicationContext.cacheDir;
            let dirPath = cacheDir + "/dir1/dir2/dir3";
            fs.mkdir(dirPath,true, (err: BusinessError) => {
              //true 创建多层级目录
              if (err) {
                console.error("mkdir failed with error message: " + err.message + ", error code: " + err.code);
              } else {
                console.info("mkdir succeed");
              }
            });
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
分享
微博
QQ
微信
回复
2024-10-16 15:18:39
相关问题