Valid File Path
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 31 16:45:01 PDT 2017
On Thursday, August 31, 2017 23:23:17 Vino via Digitalmars-d-learn wrote:
> On Thursday, 31 August 2017 at 21:59:22 UTC, vino wrote:
> > Hi All,
> >
> > Can you help me what is wrong in the below program, as the
> >
> > output is empty.
> >
> > import std.stdio, std.path;
> >
> > void main ()
> > {
> > version (Windows)
> > {
> > auto Path = `C:\#Users\Admin\Desktop\Script\Test1`;
> > if(!Path.isValidPath) { writeln("Path Not Valid");}
> > }
> > }
> >
> > From,
> > Vino.B
>
> Hi,
>
> The path is not valid as it contains the character # after the
> drive name.
And why would that not be valid? isValidPath and isValidFilename are quite
specific about what they think are valid path/file names, and having a # in
a file name is perfectly legitimate. They do have some extra restrictions
for Windows, since Windows is a lot pickier about its filenames than the
rest of the world, but # is not one of the characters listed as invalid:
https://dlang.org/phobos/std_path.html#isValidPath
https://dlang.org/phobos/std_path.html#isValidFilename
It would be invalid to have # as a drive name, but it's perfectly legal in a
filename or directory name.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list