Checking path name

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Dec 18 00:40:36 UTC 2023


On Thursday, December 14, 2023 12:33:36 PM MST cc via Digitalmars-d-learn 
wrote:
> On Thursday, 14 December 2023 at 09:38:30 UTC, Joel wrote:
> > On Thursday, 14 December 2023 at 08:47:49 UTC, Anonymouse wrote:
> >> On Thursday, 14 December 2023 at 03:58:37 UTC, Joel wrote:
> >> https://dlang.org/phobos/std_path.html#isValidPath
> >>
> >> https://dlang.org/phobos/std_path.html#.isValidFilename
> >
> > Oh, forgot about std.path
> >
> > But what's the difference between path and file name?
>
> File name can't contain path separators.

While that's true to a point, most code, documentation, and programmers
really aren't going to distinguish between the two.

When anything talks about a file path, it's pretty clear that it's talking
about relative and/or absolute file paths, and thus, file / path separators
will often be involved. However, when talking about a file name, it could be
just the file's name without any preceding path, or it could be its entire
file path (absolute or relative). It really depends on who's talking and
what the context is. And it's not uncommon for documentation on functions to
use the term path and filename interchangeably.

Ultimately though, with regards to Phobos, std.path is for functions that
have to do with manipulating file paths without actually doing anything to
files on disk. They're basically a bunch of file-specific string
manipulation functions. That then mostly relates to stuff like separators,
but it also involves stuff like file extensions.

On the other hand, std.file is for actually manipulating files rather than
the paths to files. So, it has stuff for checking whether a file on disk is
a file or a directory, whether it exists, etc. - and of course, it has
functions for reading in and writing to files.

std.stdio also has some functions for reading from and writing to files, but
the difference there is that it does it in pieces, whereas std.file reads
and writes files as single units (e.g. std.stdio might read in a file 4096
bytes at a time, whereas std.file would read it all in at once as a single
array).

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list