Thread overview
Checking path name
Dec 14
Joel
Dec 14
Joel
Dec 14
cc
Dec 14
Basile B.
December 14

If I get user input, for example, how do I check to see if it's a valid path, like, file name.

// something like this:
if (getUserInput.isValidPath) {
...
}
December 14

On Thursday, 14 December 2023 at 03:58:37 UTC, Joel wrote:

>

If I get user input, for example, how do I check to see if it's a valid path, like, file name.

// something like this:
if (getUserInput.isValidPath) {
...
}

Is that not how it works?

https://dlang.org/phobos/std_path.html#isValidPath

https://dlang.org/phobos/std_path.html#.isValidFilename

December 14

On Thursday, 14 December 2023 at 08:47:49 UTC, Anonymouse wrote:

>

On Thursday, 14 December 2023 at 03:58:37 UTC, Joel wrote:

>

If I get user input, for example, how do I check to see if it's a valid path, like, file name.

// something like this:
if (getUserInput.isValidPath) {
...
}

Is that not how it works?

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?

December 14

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.

December 14

On Thursday, 14 December 2023 at 03:58:37 UTC, Joel wrote:

>

If I get user input, for example, how do I check to see if it's a valid path, like, file name.

// something like this:
if (getUserInput.isValidPath) {
...
}

https://dlang.org/phobos/std_file.html#exists

December 17
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