Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@capacitor/filesystem: How to check if a folder/directory exists or not?

In my ionic capacitor app, I need to check if a folder exists or not on my device. But I have not found any method in the FileSystem plugin. Although there is a method for reading all the contents inside a directory.

In my case, at first, I need to check if the directory already exists or not. If it is not found, then I will create the directory.

like image 461
Uddip Acharjee Shuvo Avatar asked Oct 16 '25 11:10

Uddip Acharjee Shuvo


1 Answers

In try block write the code for creating a directory. An exception will be thrown otherwise.

    try {
      let ret = await Filesystem.mkdir({
        path: folderName,
        directory: FilesystemDirectory.Documents,
        recursive: false,
      });
      console.log("folder ", ret);
    } catch (e) {
      //console.error("Unable to make directory", e);
    }
  
like image 145
sajib006 Avatar answered Oct 19 '25 12:10

sajib006



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!