digitalmars.D.learn - Checking path name
- Joel (8/8) Dec 13 2023 If I get user input, for example, how do I check to see if it's a
- Anonymouse (4/12) Dec 14 2023 Is that not how it works?
- Joel (3/16) Dec 14 2023 Oh, forgot about std.path
- cc (2/9) Dec 14 2023 File name can't contain path separators.
- Jonathan M Davis (26/37) Dec 17 2023 While that's true to a point, most code, documentation, and programmers
- Basile B. (2/10) Dec 14 2023 https://dlang.org/phobos/std_file.html#exists
If I get user input, for example, how do I check to see if it's a valid path, like, file name. ```d // something like this: if (getUserInput.isValidPath) { ... } ```
Dec 13 2023
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. ```d // 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
Dec 14 2023
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?If I get user input, for example, how do I check to see if it's a valid path, like, file name. ```d // 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
Dec 14 2023
On Thursday, 14 December 2023 at 09:38:30 UTC, Joel wrote:On Thursday, 14 December 2023 at 08:47:49 UTC, Anonymouse wrote:File name can't contain path separators.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#.isValidFilenameOh, forgot about std.path But what's the difference between path and file name?
Dec 14 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: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 DavisOn Thursday, 14 December 2023 at 08:47:49 UTC, Anonymouse wrote:File name can't contain path separators.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#.isValidFilenameOh, forgot about std.path But what's the difference between path and file name?
Dec 17 2023
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. ```d // something like this: if (getUserInput.isValidPath) { ... } ```https://dlang.org/phobos/std_file.html#exists
Dec 14 2023