Valid directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan T

    Valid directory

    How do I check if the directory path is valid and exists ?

    eg.
    \\myserver\temp \\\\\\

    c:\temp\\doc\\\ \\\root1



  • TonySantolaria@gmail.com

    #2
    Re: Valid directory


    Alan T wrote:
    How do I check if the directory path is valid and exists ?
    >
    eg.
    \\myserver\temp \\\\\\
    >
    c:\temp\\doc\\\ \\\root1


    System.IO.Direc tory.Exists(@"c :\temp");


    cheers

    Comment

    • John Timney \(MVP\)

      #3
      Re: Valid directory

      The system.io class has a directory exists method

      Directory.Exist s(path)

      described here:



      As long as you have the authenticated rights to check that location it will
      tell you if a path exists.

      --
      Regards

      John Timney (MVP)


      "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
      news:ue936QByGH A.3568@TK2MSFTN GP03.phx.gbl...
      How do I check if the directory path is valid and exists ?
      >
      eg.
      \\myserver\temp \\\\\\
      >
      c:\temp\\doc\\\ \\\root1
      >
      >
      >

      Comment

      • Alan T

        #4
        Re: Valid directory

        I just wonder
        c:\temp\\doc\\\ root1\\\

        it gives me that is valid directory but I need to get rid of the extra '\'s
        The system.io class has a directory exists method
        >
        Directory.Exist s(path)
        >
        described here:
        >

        >
        As long as you have the authenticated rights to check that location it
        will tell you if a path exists.
        >How do I check if the directory path is valid and exists ?
        >>
        >eg.
        >\\myserver\tem p\\\\\\
        >>
        >c:\temp\\doc\\ \\\\root1

        Comment

        • John Timney \(MVP\)

          #5
          Re: Valid directory

          read how to trim here



          --
          Regards

          John Timney (MVP)


          "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
          news:eXcn18kyGH A.4392@TK2MSFTN GP04.phx.gbl...
          >I just wonder
          c:\temp\\doc\\\ root1\\\
          >
          it gives me that is valid directory but I need to get rid of the extra
          '\'s
          >
          >The system.io class has a directory exists method
          >>
          >Directory.Exis ts(path)
          >>
          >described here:
          >>
          >http://msdn2.microsoft.com/en-us/lib...ry.exists.aspx
          >>
          >As long as you have the authenticated rights to check that location it
          >will tell you if a path exists.
          >>How do I check if the directory path is valid and exists ?
          >>>
          >>eg.
          >>\\myserver\te mp\\\\\\
          >>>
          >>c:\temp\\doc\ \\\\\root1
          >
          >

          Comment

          • Alan T

            #6
            Re: Valid directory

            Sorry, I don't follow the article if it helps in my problem.

            Is there a way to get rid of the extra '\' in the directory string?

            "John Timney (MVP)" <x_john@timney. eclipse.co.ukwr ote in message
            news:XbOdnfKrXK WDN2_ZRVnyhw@ec lipse.net.uk...
            read how to trim here
            >

            >
            --
            Regards
            >
            John Timney (MVP)
            >
            >
            "Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
            news:eXcn18kyGH A.4392@TK2MSFTN GP04.phx.gbl...
            >>I just wonder
            >c:\temp\\doc\\ \root1\\\
            >>
            >it gives me that is valid directory but I need to get rid of the extra
            >'\'s
            >>
            >>The system.io class has a directory exists method
            >>>
            >>Directory.Exi sts(path)
            >>>
            >>described here:
            >>>
            >>http://msdn2.microsoft.com/en-us/lib...ry.exists.aspx
            >>>
            >>As long as you have the authenticated rights to check that location it
            >>will tell you if a path exists.
            >>>How do I check if the directory path is valid and exists ?
            >>>>
            >>>eg.
            >>>\\myserver\t emp\\\\\\
            >>>>
            >>>c:\temp\\doc \\\\\\root1
            >>
            >>
            >
            >

            Comment

            • Morten Wennevik

              #7
              Re: Valid directory

              Hi Alan,

              The article explains how to do string manipulation

              Basically, if you have a string of several \ where there should be only 1
              you can do it like this

              string s = @"c:\windows\\m icrosoft.net\\\ framework\\\";

              while (s.IndexOf(@"\\ ") -1)
              s = s.Replace(@"\\" , @"\");

              The @ means treat \ as a backslash, not as an escape character




              On Tue, 10 Oct 2006 05:16:45 +0200, Alan T <alanpltseNOSPA M@yahoo.com.au
              wrote:
              Sorry, I don't follow the article if it helps in my problem.
              >
              Is there a way to get rid of the extra '\' in the directory string?
              >
              "John Timney (MVP)" <x_john@timney. eclipse.co.ukwr ote in message
              news:XbOdnfKrXK WDN2_ZRVnyhw@ec lipse.net.uk...
              >read how to trim here
              >>
              >http://www.csharphelp.com/archives4/archive616.html
              >>
              >--
              >Regards
              >>
              >John Timney (MVP)
              >>
              >>
              >"Alan T" <alanpltseNOSPA M@yahoo.com.auw rote in message
              >news:eXcn18kyG HA.4392@TK2MSFT NGP04.phx.gbl.. .
              >>I just wonder
              >>c:\temp\\doc\ \\root1\\\
              >>>
              >>it gives me that is valid directory but I need to get rid of the extra
              >>'\'s
              >>>
              >>>The system.io class has a directory exists method
              >>>>
              >>>Directory.Ex ists(path)
              >>>>
              >>>described here:
              >>>>
              >>>http://msdn2.microsoft.com/en-us/lib...y.exists..aspx
              >>>>
              >>>As long as you have the authenticated rights to check that locationit
              >>>will tell you if a path exists.
              >>>>How do I check if the directory path is valid and exists ?
              >>>>>
              >>>>eg.
              >>>>\\myserver\ temp\\\\\\
              >>>>>
              >>>>c:\temp\\do c\\\\\\root1
              >>>
              >>>
              >>
              >>
              >
              >


              --
              Happy Coding!
              Morten Wennevik [C# MVP]

              Comment

              Working...