5 Replies - 3001 Views - Last Post: 28 November 2011 - 09:29 AM Rate Topic: -----

#1 Cookie.90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 19-April 10

Select a Root Directory and Search all sub folders

Posted 28 November 2011 - 07:44 AM

Hi all,

I am currently using the
 Directory.GetFiles("Path of folder", "Specific Data") 

to search a folder for specific files and then do something with those files - this works perfectly. However i would like to search all sub folders within the top level folder also.

I have seen ways to return what directories exist within the top level - which i could then use to search but was wondering if there is an easier way.

Any help is much appreciated!

Chris

Is This A Good Question/Topic? 0
  • +

Replies To: Select a Root Directory and Search all sub folders

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9381
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: Select a Root Directory and Search all sub folders

Posted 28 November 2011 - 07:52 AM

Why not use 'getdirectories'?

http://msdn.microsof...y/c1sez4sc.aspx
Was This Post Helpful? 0
  • +
  • -

#3 Cookie.90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 19-April 10

Re: Select a Root Directory and Search all sub folders

Posted 28 November 2011 - 08:51 AM

Thank you for the quick reply.

That was the code i was looking at - but I would need a loop to go through each directory (sub folder) within the root and then continue with the process for each directory found.

Does this make sense or am i getting this wrong?

Cheers,

Chris
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9381
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: Select a Root Directory and Search all sub folders

Posted 28 November 2011 - 09:10 AM

No.. that's exactly what needs to happen. I would suggest a nice recursive function to cut down on the code!
Was This Post Helpful? 0
  • +
  • -

#5 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Select a Root Directory and Search all sub folders

Posted 28 November 2011 - 09:24 AM

of topic
@modi i hear somewhere that recursions are to be avoided at all cost and that you can always avoid recursions. though looking here lots of ppl like recursions and think they are the shit out there.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9381
  • View blog
  • Posts: 35,228
  • Joined: 12-June 08

Re: Select a Root Directory and Search all sub folders

Posted 28 November 2011 - 09:29 AM

Quote

of topic
@modi i hear somewhere that recursions are to be avoided at all cost

Who's been talking that smack? ;) At best recursion is a great tool for repetitive tasks or traversals (trees anyone?). I've used recursion on file directory traversal before and it was fine. What should be avoided is over zealous use of recursion. College tends to hit on recursion and after the pain people want to use it EVERYWHERE... even when not needed; turning an easy solution into a maintenance nightmare.


Quote

and that you can always avoid recursions.

Sure, but that's not the elegant solution now is it?

Quote

though looking here lots of ppl like recursions and think they are the shit out there.

That's the college lens they are viewing everything through. "College beat recursion into me so it *MUST* be teh supa fly!".
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1