#鸿蒙学习大百科#如何判断文件是否是目录?

如何判断文件是否是目录?

HarmonyOS
2024-10-17 09:20:33
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
花鸟吹雪
import { common } from '@kit.AbilityKit';
import fs from '@ohos.file.fs';
import { WatchEvent } from '@kit.CoreFileKit';

@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;
            fs.statSync(cacheDir+"/test.txt").isDirectory()//true:目录   false:文件
          })
      }
      .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.
分享
微博
QQ
微信
回复
2024-10-17 14:46:17
相关问题
#鸿蒙学习大百科#什么用户文件
1021浏览 • 0回复 待解决
#鸿蒙学习大百科#什么LocalStorage?
1066浏览 • 1回复 待解决
#鸿蒙学习大百科#什么AppStorage?
917浏览 • 1回复 待解决
#鸿蒙学习大百科#什么HiTraceMeter?
961浏览 • 1回复 待解决
#鸿蒙学习大百科#什么组合手势?
1053浏览 • 1回复 待解决
#鸿蒙学习大百科#什么应用沙箱?
1242浏览 • 1回复 待解决
#鸿蒙学习大百科#什么隐式Want?
1095浏览 • 1回复 待解决