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. Need help in File handling with directory

Need help in File handling with directory

Scheduled Pinned Locked Moved C#
csharpc++helpquestion
3 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.
  • A Offline
    A Offline
    Ashraj1982
    wrote on last edited by
    #1

    Hi All, Can any one give me the suitable functions for the following in c# : 1. To find first instance of a file name that matches the file specification like *.jpg? like _tfindfirst( ) function in vc++ 2.To find the next name, if any, that matches the file specification? like _tfindfirst( ) function in VC++ 3. To find the Sub Directory? like _A_SUBDIR( ) function in vc++ 4. To ignore directory with . and .. ? Thanks

    L 1 Reply Last reply
    0
    • A Ashraj1982

      Hi All, Can any one give me the suitable functions for the following in c# : 1. To find first instance of a file name that matches the file specification like *.jpg? like _tfindfirst( ) function in vc++ 2.To find the next name, if any, that matches the file specification? like _tfindfirst( ) function in VC++ 3. To find the Sub Directory? like _A_SUBDIR( ) function in vc++ 4. To ignore directory with . and .. ? Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Fore more file specification, please read FileInfo Help. The subdirectory . and .. are ignored.

      static FileInfo FindFile(string startDirectory, string extension)
      {
      DirectoryInfo di = new DirectoryInfo(startDirectory);
      foreach(FileInfo fi in di.GetFiles())
      {
      if(fi.Extension.ToLower() == extension)
      return fi;
      }
      return null;
      }

      static DirectoryInfo FindDirectory(string startDirectory, string dirNameToSearch)
      {
      DirectoryInfo di = new DirectoryInfo(startDirectory);
      foreach(DirectoryInfo diSearch in di.GetDirectories())
      {
      if(diSearch.Name == dirNameToSearch)
      return diSearch;
      }
      return null;
      }

      J 1 Reply Last reply
      0
      • L Lost User

        Fore more file specification, please read FileInfo Help. The subdirectory . and .. are ignored.

        static FileInfo FindFile(string startDirectory, string extension)
        {
        DirectoryInfo di = new DirectoryInfo(startDirectory);
        foreach(FileInfo fi in di.GetFiles())
        {
        if(fi.Extension.ToLower() == extension)
        return fi;
        }
        return null;
        }

        static DirectoryInfo FindDirectory(string startDirectory, string dirNameToSearch)
        {
        DirectoryInfo di = new DirectoryInfo(startDirectory);
        foreach(DirectoryInfo diSearch in di.GetDirectories())
        {
        if(diSearch.Name == dirNameToSearch)
        return diSearch;
        }
        return null;
        }

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        Well done, you just did this guys homework! Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

        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