directorymicrosoft-edgenative-file-system-api-jsfile-system-access-api

Edge browser Native File System removeEntry use


I'm working with the newest version of Edge (Canary release 86.0.615.0) and I can get the new Native File System API showOpenFilePicker to let me access files but I can't find a reference to the directoryHandle functions including the removeEntry function if the user elects to remove the file. Am I missing a special flag? I have an Origin-Tracker code and I also have the experimental flag set for the Native File System API.


Solution

  • If you have a directory handle, you can delete files or folders as in the example below:

    // Delete a file.
    await directoryHandle.removeEntry('Abandoned Projects.txt');
    // Recursively delete a folder.
    await directoryHandle.removeEntry('Old Stuff', { recursive: true });
    

    You can obtain a directory handle from the picker:

    const directoryHandle = await window.showDirectoryPicker();
    

    To iterate over the entries of a directory, you can use the code snippet below:

    for await (const entry of directoryHandle.values()) {
      console.log(entry.kind, entry.name);
    }