Skip to content

Directory Listing

SWS provides a directory listing feature to display the content of directories.

This feature is disabled by default and can be controlled by the boolean -z, --directory-listing option or the equivalent SERVER_DIRECTORY_LISTING env.

static-web-server \
    --port 8787 \
    --root ./my-public-dir \
    --directory-listing true

And here an example of how the directory listing looks like.

Sorting

Sorting by Name, Last modified and Size is enabled as clickable columns when the directory listing is activated via the --directory-listing=true option.

You can also use the sort query parameter to sort manually by certain attributes from URI. E.g https://localhost/?sort=5.

Sorting by default

Sometimes one wants to sort by certain attribute but by default. In that case, the default ascending or descending ordering of files/dirs by their attributes is provided by the numeric --directory-listing-order option or the equivalent SERVER_DIRECTORY_LISTING_ORDER env.

To do so you have to pass a code sorting number. E.g --directory-listing-order=2.

Code numbers for sorting

Below are the possible number code values for sorting or ordering which are grouped by attribute.

Name

  • 0: Ascending
  • 1: Descending

Last modified

  • 2: Ascending
  • 3: Descending

Size

  • 4: Ascending
  • 5: Descending

Default

  • 6: Unordered

Tips

  • The --directory-listing-order option depends on --directory-listing to be enabled.
  • Use the query ?sort=NUMBER to customize the sorting via the URI. E.g https://localhost/?sort=5 (sort by size in descending order)

Example:

static-web-server \
    --port 8787 \
    --root ./my-public-dir \
    --directory-listing true \
    # E.g Sorting file/dir names in descending order
    --directory-listing-order 1
Back to top