Cute File Browser

I found this very neat jQuery based file browser:

http://tutorialzine.com/2014/09/cute-file-browser-jquery-ajax-php/

This uses a simply PHP script to form JSON output defining the filesystem, however in my case I want to serve files on a Windows PC using just static content. This is relatively easy to code – we just need to create the file listing in advance, e.g. into something called files.json, and modify the javascript to retrieve this instead of scan.php.

My batch script to do that is listed here – it simply scans recursively from the current directory creating the necessary JSON on the output; you can pipe it to the appropriate location for the files.json output.

@echo off
setlocal enableextensions disabledelayedexpansion

set p=%1
set n=%2
set comma=
set oldcomma=X

call:funcdo "%1" "%2"

endlocal
goto:eof

:funcdo
setlocal
set "p=%~1"
set "n=%~2"

echo {"name":"%n%","type":"folder","path":"%p%","items":[

set oldcomma=%oldcomma%%comma%
set comma=N

for /d %%d in (*) do (
    cd "%%d"
    call:funcdo "%p%/%%d" "%%d"
    echo ,
    cd ..
)

for /f "tokens=*" %%f in ('dir /b *.divx *.mpg *.mpeg *.avi *.mkv *.mp4 *.wmv 2^>nul ^| sort') do (
    echo {"name":"%%f","type":"file","path":"%p%/%%f","size":"%%~zf"},
)

echo {}]}

set comma=%oldcomma:~-1%
set oldcomma=%oldcomma:~0,-1%
endlocal
goto:eof

It’s not very polished and could no doubt be improved, but it works.

Leave a Reply

Your email address will not be published. Required fields are marked *