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. Search files

Search files

Scheduled Pinned Locked Moved C#
tutorial
2 Posts 2 Posters 6 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
    Makyana
    wrote on last edited by
    #1

    How to search for files/folders and adding all the found filenames to a collection. For exemple : Search all "*.url" files on "C:" Thanks

    A 1 Reply Last reply
    0
    • M Makyana

      How to search for files/folders and adding all the found filenames to a collection. For exemple : Search all "*.url" files on "C:" Thanks

      A Offline
      A Offline
      Andreas Philipson
      wrote on last edited by
      #2

      The things you need is located in the namespace System.IO... I would do it like this:

      using System.IO;

      public void FindFiles (string path)
      {
      if (Directory.Exists (path))
      {
      DirectoryInfo thisDir = new DirectoryInfo (path);
      FileInfo [] files = thisDir.GetFiles ("*url");
      DirectoryInfo [] subDirs = thisDir.GetDirectories ();

      foreach (FileInfo f in files)
      {
        //Do what you should with the files...
      }
      
      foreach (DirectoryInfo d in subDirs)
      {
        FindFiles (d.FullName);
      }
      

      }
      }

      Andreas Philipson

      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