PHP/file/name: Difference between revisions

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
No edit summary
m Woozle moved page PHP/file/sys to PHP/file/name: more accurate
(No difference)

Revision as of 12:42, 7 September 2022

Template:Fmt/title

Template:Box/nav

About

PHP's functionality for managing and accessing file/folder names/paths is a mix of classes and standalone functions.

Native Functions

Any of the following can be used to get a directory listing:

  • Template:Fmt/code accepts a filepath to an existing folder and returns a Template:Fmt/code object, which can be iterated through to get the listing.
    • Sorting must be done after retrieving all the files.
    • It seems likely (I haven't tested this) that the iteration process is atomic by file, i.e. it will return from listing one file even if the directory is damaged and the next one cannot be read.
  • Template:Fmt/code: see Template:L/same
  • Template:Fmt/code accepts a filename and a glob-mask, and tells whether the filename fits the mask
  • Template:Fmt/code accepts a filepath to an existing folder and returns an array of files found in the given folder. By default, they are sorted alphabetically.

The following functions can parse a filespec in various ways:

Reference