{dir}

Lists the names in a directory, one occurrence each - the plain version of files.

Files Tag pairs

Syntax

{dir $path} {$dir} {/dir}

Parameters

path
The directory, used as given - an absolute path, built from APP or DATA. It must lie inside the applications, the engine or DATA.

Description

{dir $path} lists the names in a directory as its data, one occurrence per entry with the name in {$dir} - . and .. left out, the others sorted as PHP's scandir sorts them. Files and directories come alike, hidden ones too, and nothing below is scanned.

The path is used as given, so build it from the APP or DATA constant - a relative path is read from the server's working directory, which differs between the web server and the command line. It must lie inside the applications, the engine or DATA. A directory that is not there is an error under the strict check, an empty list without it.

{files} does the same with a base, masks, recursion and a field per entry.

Examples

The names in a directory

One occurrence per entry, its name in {$dir} - . and .. left out, the names sorted as scandir sorts them.

Templateexamples/dir/1-list.pad
<ul>
{dir $folder}
  <li>{$dir}</li>
{/dir}
</ul>
PHPexamples/dir/1-list.php
<?php

  $folder = APP . '_data/filesDemo';

?>
Resultopen alone
  • archive
  • notes.txt
  • prices.csv
  • readme.md

Counted and joined

The entries are data like any other: a property of the loop, a separator between them.

Templateexamples/dir/2-count.pad
{set $folder = APP . '_data/filesDemo/archive'}
<p>{dir $folder}{first@dir}{count@dir} reports: {/first@dir}{notFirst@dir}, {/notFirst@dir}{$dir}{/dir}</p>
Resultopen alone

2 reports: 2025.txt, 2026.txt

See also

  • {files} Scans a directory and iterates its entries, with path, file, ext, item and dir for each.
  • {exists} Renders its content when a file or directory is there, its else half when not.