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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Direcroty search

Direcroty search

Scheduled Pinned Locked Moved C#
helptutorialquestion
2 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.
  • R Offline
    R Offline
    Ronni Marker
    wrote on last edited by
    #1

    Hello All, Have a "minor" issue that i hope someone here can help me with. I have the following code [Example below] that runs throu all directories to find specific files (eg. doc files). When the code is run from a user who have admin right, then there are no issues. but if its run as a user with no rights whatsoever i get into trouble. Running in the directory C:\documents and settings with the folders Administrator, Admin, Lousy User, Teds & BillG. When the code is run in standard user mode, it will stop executing the folders in that thread when there is no access rights on a folder - in this case it will begin with Administrator folder first, and stop search in that directory. meaning it will newer get to search the users own folder "Lousy User". Is there any was to get over this issue? hope u all understood my meaning by this. try { foreach (string d in Directory.GetDirectories(sDir)) { foreach (string f in Directory.GetFiles(d, filetype)) { FileInfo fs = new FileInfo(f); view.Items.Add(itm); } } } catch (System.Exception excpt) { // Console.WriteLine(excpt.Message); }

    C 1 Reply Last reply
    0
    • R Ronni Marker

      Hello All, Have a "minor" issue that i hope someone here can help me with. I have the following code [Example below] that runs throu all directories to find specific files (eg. doc files). When the code is run from a user who have admin right, then there are no issues. but if its run as a user with no rights whatsoever i get into trouble. Running in the directory C:\documents and settings with the folders Administrator, Admin, Lousy User, Teds & BillG. When the code is run in standard user mode, it will stop executing the folders in that thread when there is no access rights on a folder - in this case it will begin with Administrator folder first, and stop search in that directory. meaning it will newer get to search the users own folder "Lousy User". Is there any was to get over this issue? hope u all understood my meaning by this. try { foreach (string d in Directory.GetDirectories(sDir)) { foreach (string f in Directory.GetFiles(d, filetype)) { FileInfo fs = new FileInfo(f); view.Items.Add(itm); } } } catch (System.Exception excpt) { // Console.WriteLine(excpt.Message); }

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Off the top of my head, I'm guessing that an exception is thrown if you don't have access to the directory you are trying to get the files for. If that is the case then your try catch block should be around the inner loop rather than the outer loop - that will allow you to continue searching in other directories, at the moment as soon as a directory is encountered that you don't have permission to view an exception is thrown that will stop the rest of your process. Does this help?


      "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell The Second EuroCPian Event will be in Brussels on the 4th of September Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!

      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