Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. list subdirectories with specific names

list subdirectories with specific names

Scheduled Pinned Locked Moved C#
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrKBA
    wrote on last edited by
    #1

    Hi, I have to get list of subdirectoris in parent folder ("A_ParentDir") which have names in format "vX.XX" where X is numeric. Example : I have folder A_ParentDir which contains list of directories as below : v3.20 v4.56 v8.1 v5.60a v6.00v6.00 so I should have only : v3.20 v4.56 I tried as below but I have also the last one in result v3.20 v4.56 v6.00v6.00 // this shouldn't be

    string strreg = @"v\d{1}\.{1}\d{2}$";

    arrVersionsDirectories = Directory.GetDirectories(A_ParentDir)
    .Where(path => Regex.IsMatch(path, strreg))
    .ToList();

    thank for help

    OriginalGriffO 2 Replies Last reply
    0
    • M MrKBA

      Hi, I have to get list of subdirectoris in parent folder ("A_ParentDir") which have names in format "vX.XX" where X is numeric. Example : I have folder A_ParentDir which contains list of directories as below : v3.20 v4.56 v8.1 v5.60a v6.00v6.00 so I should have only : v3.20 v4.56 I tried as below but I have also the last one in result v3.20 v4.56 v6.00v6.00 // this shouldn't be

      string strreg = @"v\d{1}\.{1}\d{2}$";

      arrVersionsDirectories = Directory.GetDirectories(A_ParentDir)
      .Where(path => Regex.IsMatch(path, strreg))
      .ToList();

      thank for help

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      You need to add a "start of string" indicator to your regex:

      string strreg = @"^v\d{1}\.{1}\d{2}$";

      But a simpler to read version would be:

      string strreg = @"^v\d\.\d\d$";

      If you are going to use Regexes, then I'd suggest you get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        You need to add a "start of string" indicator to your regex:

        string strreg = @"^v\d{1}\.{1}\d{2}$";

        But a simpler to read version would be:

        string strreg = @"^v\d\.\d\d$";

        If you are going to use Regexes, then I'd suggest you get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        M Offline
        M Offline
        MrKBA
        wrote on last edited by
        #3

        you saved me

        OriginalGriffO 1 Reply Last reply
        0
        • M MrKBA

          Hi, I have to get list of subdirectoris in parent folder ("A_ParentDir") which have names in format "vX.XX" where X is numeric. Example : I have folder A_ParentDir which contains list of directories as below : v3.20 v4.56 v8.1 v5.60a v6.00v6.00 so I should have only : v3.20 v4.56 I tried as below but I have also the last one in result v3.20 v4.56 v6.00v6.00 // this shouldn't be

          string strreg = @"v\d{1}\.{1}\d{2}$";

          arrVersionsDirectories = Directory.GetDirectories(A_ParentDir)
          .Where(path => Regex.IsMatch(path, strreg))
          .ToList();

          thank for help

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Ignore the previous answer! I forgot the folder path was there... :-O Best way is to do this:

          string strreg = @"^v\d\.\d\d{2}$";

          arrVersionsDirectories = Directory.GetDirectories(A_ParentDir)
          .Where(path => Regex.IsMatch(Path.GetFileName(path), strreg))
          .ToList()

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • M MrKBA

            you saved me

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            Nope - see my other reply! :-O

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups