Assuming you are using Windows, you can use a batch file to generate a JSON representing your directory structure:
dir2json.bat [diretório] >[arquivo destino]
Example:
dir2json.bat . >lista.json
dir2json.bat
@echo off &setlocal
setlocal EnableDelayedExpansion
if "%~1"=="" (set "root=.") else set "root=%~1"
set "pre0= "
pushd %root%
echo([
call:dirtree "%CD%" "1" "1"
popd
echo(]
goto:eof
:dirtree
setlocal
call set "pre=%%pre0:~-%~2%%
set /a ccount=%~3
set /a tcount=%~2+2
set /a dcount=0
set /a fcount=0
for /d %%i in (*) do set /a dcount+=1
echo( [
{
"type": "folder",
"name": "libs",
"path": "C:/teste/libs",
"childno": 1,
"files": [
{"type":"file","name": "dir.txt"},
{"type":"file","name": "tree2json.bat"}
],
"subchilds": 5,
"children": [
{
"type": "folder",
"name": "bf",
"path": "C:/teste/libs/bf/bf",
"childno": 5,
"files": [
{"name": "authentication.js"},
{"name": "item.js"},
{"name": "menu.js"},
{"name": "person.js"}
],
"subchilds": 0
},
[...]
{
echo( dir2json.bat [diretório] >[arquivo destino]
"type": "folder",
echo( dir2json.bat . >lista.json
"name": "%~nx1",
set "fpath=%~f1"
set "fpath=%fpath:\=/%"
echo( @echo off &setlocal
setlocal EnableDelayedExpansion
if "%~1"=="" (set "root=.") else set "root=%~1"
set "pre0= "
pushd %root%
echo([
call:dirtree "%CD%" "1" "1"
popd
echo(]
goto:eof
:dirtree
setlocal
call set "pre=%%pre0:~-%~2%%
set /a ccount=%~3
set /a tcount=%~2+2
set /a dcount=0
set /a fcount=0
for /d %%i in (*) do set /a dcount+=1
echo( [
{
"type": "folder",
"name": "libs",
"path": "C:/teste/libs",
"childno": 1,
"files": [
{"type":"file","name": "dir.txt"},
{"type":"file","name": "tree2json.bat"}
],
"subchilds": 5,
"children": [
{
"type": "folder",
"name": "bf",
"path": "C:/teste/libs/bf/bf",
"childno": 5,
"files": [
{"name": "authentication.js"},
{"name": "item.js"},
{"name": "menu.js"},
{"name": "person.js"}
],
"subchilds": 0
},
[...]
{
echo( %pre%"type": "folder",
echo( %pre%"name": "%~nx1",
set "fpath=%~f1"
set "fpath=%fpath:\=/%"
echo( %pre%"path": "%fpath%",
echo( %pre%"childno": %ccount%,
for %%i in (*) do set /a fcount+=1
if %fcount% gtr 0 (
echo( %pre%"files": [
for %%i in (*) do (
echo( %pre%{"name": "%%i"}
set /A fcount-=1
if !fcount! gtr 0 (echo %pre%,)
)
echo( %pre%],
)
)
if %dcount% equ 0 echo( %pre%"subchilds": %dcount%
if %dcount% gtr 0 (
echo( %pre%"subchilds": %dcount%,
echo( %pre%"children": [
for /d %%i in (*) do (
for /f %%j in ('call echo "%%dcount%%"') do (
cd "%%i"
call:dirtree "%%i" "%tcount%" "%%j"
cd ..
)
set /a dcount-=1
)
echo( %pre%]
)
if %ccount% equ 1 (echo %pre%}) else echo( %pre%},
endlocal
goto:eof
"path": "%fpath%",
echo( %pre%"childno": %ccount%,
for %%i in (*) do set /a fcount+=1
if %fcount% gtr 0 (
echo( %pre%"files": [
for %%i in (*) do (
echo( %pre%{"name": "%%i"}
set /A fcount-=1
if !fcount! gtr 0 (echo %pre%,)
)
echo( %pre%],
)
)
if %dcount% equ 0 echo( %pre%"subchilds": %dcount%
if %dcount% gtr 0 (
echo( %pre%"subchilds": %dcount%,
echo( %pre%"children": [
for /d %%i in (*) do (
for /f %%j in ('call echo "%%dcount%%"') do (
cd "%%i"
call:dirtree "%%i" "%tcount%" "%%j"
cd ..
)
set /a dcount-=1
)
echo( %pre%]
)
if %ccount% equ 1 (echo %pre%}) else echo( %pre%},
endlocal
goto:eof
Your end result will look something like this:
%pre%
Source: Adapted version of link
(The original version lists only subdirectories. The adapted version also includes files.)