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. File masks

File masks

Scheduled Pinned Locked Moved C#
questioncsharp
4 Posts 3 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.
  • G Offline
    G Offline
    Guinness4Strength
    wrote on last edited by
    #1

    I'd like to compare a user specified file mask with a given file. I can write my own function, but many of the .NET methods use this ability and I was wondering if it was hiding someplace ? So my question is simple, does anyone know of a .Net method that will allow me to compare a file and file spec (file mask) ? i.e. compare all the files in System32 to *.d??

    H 1 Reply Last reply
    0
    • G Guinness4Strength

      I'd like to compare a user specified file mask with a given file. I can write my own function, but many of the .NET methods use this ability and I was wondering if it was hiding someplace ? So my question is simple, does anyone know of a .Net method that will allow me to compare a file and file spec (file mask) ? i.e. compare all the files in System32 to *.d??

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      See the DirectoryInfo.GetFiles method:

      DirectoryInfo di = new DirectoryInfo(
      Environment.GetFolderPath(Environment.SpecialFolder.System));
      FileInfo[] fis = di.GetFiles("*.d");
      if (fis != null)
      foreach (FileInfo fi in fis)
      Console.WriteLine(fi.FullName);

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      G 1 Reply Last reply
      0
      • H Heath Stewart

        See the DirectoryInfo.GetFiles method:

        DirectoryInfo di = new DirectoryInfo(
        Environment.GetFolderPath(Environment.SpecialFolder.System));
        FileInfo[] fis = di.GetFiles("*.d");
        if (fis != null)
        foreach (FileInfo fi in fis)
        Console.WriteLine(fi.FullName);

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        G Offline
        G Offline
        Guinness4Strength
        wrote on last edited by
        #3

        This is the way I'm doing it now. I'm actually getting the filename off a socket. So I create a dir and write a zero-length file using the file name then use the Directory.GetFiles() method. I just didn't know if there was a method that I could specify the file name and mask and get a boolean result, or something along those lines, so I don't have to write to disk. Thanks for your help as usual Heath. -Mike

        B 1 Reply Last reply
        0
        • G Guinness4Strength

          This is the way I'm doing it now. I'm actually getting the filename off a socket. So I create a dir and write a zero-length file using the file name then use the Directory.GetFiles() method. I just didn't know if there was a method that I could specify the file name and mask and get a boolean result, or something along those lines, so I don't have to write to disk. Thanks for your help as usual Heath. -Mike

          B Offline
          B Offline
          Broken God
          wrote on last edited by
          #4

          Well, you could generate a regex out of the mask. Add "^" to the beginning. Add "$" to the end. Replace "*" with ".*". Replace "?" with ".". And that should do it. Although you'll need to escape some characters like "(", "+", "." and "[" and a lot more.

          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