question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

directoryOpen does not allow creating new files in an empty directory

See original GitHub issue

directoryOpen() returns a 0 length array of FileWithDirectoryAndFileHandle if there is nothing inside the directory having been opened. In my case I’m opening with a mode of readwrite, so Chrome nicely prompts me that the application will have access to the directory. Per https://wicg.github.io/file-system-access/#api-filesystemdirectoryhandle, I can create new files by calling getFileHandle(create=true) on a directory handle; however, because directoryOpen returns 0 length, I don’t have a directory handle to create the initial file in.

If there’s an alternate way to accomplish this, please advise; but, I think the fix is to include a FileSystemDirectoryHandle as part of the directoryOpen response.

(I’m making an app with no server; data is stored in localstorage, and I’m adding sync to and from the filesystem.)

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
reubenfirmincommented, Nov 24, 2022

Sure. I’m not much of a js programmer, but I followed the pattern in the codebase.

https://github.com/GoogleChromeLabs/browser-fs-access/pull/132

I chose to delegate to directoryOpen rather than reimplementing most of it - let me know what you think. I will test more thoroughly if the code looks reasonable.

0reactions
tomayaccommented, Nov 24, 2022

@beaufortfrancois suggests maybe having a completely new convenience function fileHierarchy() or so might be cleanest, which would only work if the File System Access API is supported. The point of browser-fs-access is to be a ponyfill (not polyfill), so this potential new function that only works when the File System Access API is supported would be kind of against its philosophy, but I can see how it would add value. Do you want to work on a PR that would add it as a new file file-hierarchy.mjs in src/fs-access/?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not Creating New File If Empty Directory - Stack Overflow
So when I run $create, the bot will see what user sent said command, and basically fill that variable as {ctx.author.name}. so when...
Read more >
Can't delete empty folder because it is used - Super User
Just make sure that the folder you want to delete is actually empty and has nothing important in it first. Save this answer....
Read more >
91096 – Add option so that tmpwatch can handle removing ...
Description of problem: Tmpwatch does not delete empty directories. I suspect it is because something updates each directory's access time.
Read more >
How To Work With Files In Java - Marco Behler
You can use this guide to learn how to work with files in Java through the Path API. From reading and writing files,...
Read more >
Directory.Delete Method (System.IO) - Microsoft Learn
The directory specified by path is not empty. ... The following example shows how to create a new directory, subdirectory, and file in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found