ReactJS | How to convert a local directory (with empty subdirectories) to a directory-tree JSON

92 Views Asked by At

I have a local directory with this structure (no files, only subfolders):

+ root-dir
   + sub-dir-1
      + sub-dir-1-1

   + sub-dir-2
      + sub-dir-2-1
      + sub-dir-2-1

I want to select this folder ('root-dir') from local and then generate a directory-tree JSON.

Solutions I've tried:

Input file

<input type="file" directory allowdirs webkitdirectory/>

The input file works only if there are actual files within a folder.

FileSystemDirectoryReader

https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries

Found this solution which is a non-standard solution and not recommended to use.

0

There are 0 best solutions below