B
brant.usenet
Forgive me if this has already been covered; I've searched and found
nothing related.
File.Exists() seems to clean up the path passed into its path
parameter. Specifically, it seems to 'fix' any directory names within
the path with leading or trailing spaces.
E.g. assuming a file exists at "c:\foo\bar.txt"
Likewise, the FileInfo class constructor seems to do the same cleanup:
E.g. assuming a file exists at "c:\foo\bar.txt"
This is all very accomodating, but when testing for existance of a file
at a particular path, one would almost certainly prefer a more literal
result. Or, to at least have an option for such a literal test.
There are similar issues with Directory.CreateDirectory(). It will
silently fix up one's path and return success, leaving the caller to
believe that their (admittedly bogus) path was OK.
Can anyone tell me authoritatively that this is not by design? If it is
somehow by design, by what logic? How should I perform the test I
desire?
nothing related.
File.Exists() seems to clean up the path passed into its path
parameter. Specifically, it seems to 'fix' any directory names within
the path with leading or trailing spaces.
E.g. assuming a file exists at "c:\foo\bar.txt"
File.Exists(@"C:\foo\bar.txt); --> true (OK)
File.Exists(@"C:\foo \bar.txt); --> true (incorrect)
Likewise, the FileInfo class constructor seems to do the same cleanup:
E.g. assuming a file exists at "c:\foo\bar.txt"
FileInfo f1 = new FileInfo(@"C:\foo\bar.txt");
FileInfo f2 = new FileInfo(@"C:\foo \bar.txt");
f1.Exists --> true (OK)
f1.FullName --> "C:\foo\bar.txt" (OK)
f2.Exists --> true (no)
f2.FullName --> "C:\foo\bar.txt" (!!!)
This is all very accomodating, but when testing for existance of a file
at a particular path, one would almost certainly prefer a more literal
result. Or, to at least have an option for such a literal test.
There are similar issues with Directory.CreateDirectory(). It will
silently fix up one's path and return success, leaving the caller to
believe that their (admittedly bogus) path was OK.
Can anyone tell me authoritatively that this is not by design? If it is
somehow by design, by what logic? How should I perform the test I
desire?