How i verify a path is valid or not.
like C:\abc\xy.txt if the file was not there then message will show path is not exist.
Thank you.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hiren SoniRank #694 · 3.5K reputationPosted Jul 25, 2010, 9:15 PM EDT
if (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))
{
MessageBox.Show("true");
}
else
{
MessageBox.Show("false");
}
you can check both directory or file exists or not ?
because path man be for directory or file
Lalit MRank #1,186 · 1.5K reputationPosted Jul 25, 2010, 7:53 PM EDT
using System; using System.Text.RegularExpressions; /// /// Gets whether the specified path is a valid absolute file path. /// /// Any path. OK if null or empty. static public bool IsValidPath( string path ) { Regex r = new Regex( @"^(([a-zA-Z]\:)|(\\))(\\{1}|((\\{1})[^\\]([^/:*?<>""|]*))+)$" ); return r.IsMatch( path ); }Tanmay SarkarRank #1,407 · 1.2K reputationPosted Jul 25, 2010, 8:29 PM EDT
But it can't tell a path is valid or not.
if i wrote C:\abc\xy.txt then your code tell the path is correct
but in real there is no that type of path in my com.
So i want to verify path is valid or not...
Thanks for your contribution & well code, :-)
but my problem is not solve yet...
Thank you!
Tanmay SarkarRank #1,407 · 1.2K reputationPosted Jul 25, 2010, 9:32 PM EDT