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) {
...
}
Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
December 14, 2023 Checking path name | ||||
---|---|---|---|---|
| ||||
If I get user input, for example, how do I check to see if it's a valid path, like, file name.
|
December 14, 2023 Re: Checking path name | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | 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.
Is that not how it works? |
December 14, 2023 Re: Checking path name | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anonymouse | 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.
Is that not how it works? Oh, forgot about std.path But what's the difference between path and file name? |
December 14, 2023 Re: Checking path name | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | 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: Oh, forgot about std.path But what's the difference between path and file name? File name can't contain path separators. |
December 14, 2023 Re: Checking path name | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel | 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.
|
December 17, 2023 Re: Checking path name | ||||
---|---|---|---|---|
| ||||
Posted in reply to cc | 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
|