regex pattern that takes only directory without file name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mandz
    New Member
    • Dec 2014
    • 1

    regex pattern that takes only directory without file name

    regex pattern that takes only directory without file name
    Code:
    private void txtDownloadRoot_Validating(object sender, CancelEventArgs e)
            {
                Regex driveCheck = new Regex(@"([a-zA-Z]:\\[^/:\*;\/\:\?<>\|]+)|(\\{2}[^/:\*;\/\:\?<>\|]+)");
                if (!driveCheck.IsMatch(txtDownloadRoot.Text))
                {
                    e.Cancel = true;
                    txtDownloadRoot.Focus();
                    errorProvider1.SetError(txtDownloadRoot, "invalid path...!!!");
                }
                else
                {
                    errorProvider1.SetError(this.txtDownloadRoot, String.Empty);
                }
    Last edited by Frinavale; Dec 5 '14, 02:36 PM. Reason: Added code tags.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    Why do you want to do this with a regex?

    GetFileName seems more appropriate to get the file name, after that it's easy to get the directory name.

    Comment

    Working...