Loop through all files in folder

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
Reply

Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Loop through all files in folder

 
0
  #1
Jan 4th, 2009
Hi,

This is my second post in continuation to my previous one. How can I loop through all the files in a folder.

Cheers!
Ali
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: Loop through all files in folder

 
0
  #2
Jan 4th, 2009
You can use foreach cycle. E.g. like this:
  1. foreach(string fileName f in Directory.GetFiles("SomeDirectory"))
  2. {
  3. ...
  4. }
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Loop through all files in folder

 
0
  #3
Jan 4th, 2009
Thanks, but it gives me the error that the Directory doesn't exists in the current context.

How can I declare it?

Originally Posted by Antenka View Post
You can use foreach cycle. E.g. like this:
  1. foreach(string fileName f in Directory.GetFiles("SomeDirectory"))
  2. {
  3. ...
  4. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Loop through all files in folder

 
0
  #4
Jan 4th, 2009
You dont.. Its a predefined class in .net - have a check in your helpfile, its clever and tells you what references (if necessary) and what "using" statements you would need
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: Loop through all files in folder

 
0
  #5
Jan 4th, 2009
Direcrory class placed in System.IO. So you sould add import to it:
  1. using System.IO;
Last edited by Antenka; Jan 4th, 2009 at 4:12 pm.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Loop through all files in folder

 
0
  #6
Jan 4th, 2009
Thanks, got it.

Originally Posted by Antenka View Post
Direcrory class placed in System.IO. So you sould add import to it:
  1. using System.IO;
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Loop through all files in folder

 
0
  #7
Jan 4th, 2009
How can I display a message showing the fileNames retrieved from the given directory.

1.
foreach(string fileName f in Directory.GetFiles("SomeDirectory"))
2.
{
3.
...
4.
}

Originally Posted by Antenka View Post
Direcrory class placed in System.IO. So you sould add import to it:
  1. using System.IO;
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Loop through all files in folder

 
0
  #8
Jan 4th, 2009
Have you looked at what you get in the foreach loop?
OK while that code wont work specifically it has a big raving clue in it...

What do you think the clue is?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: Loop through all files in folder

 
0
  #9
Jan 4th, 2009
When you call GetFiles method, it return to you an array of strings (filenames). To show them in the message, you should organize them in way, that you like into a string. After that you can see here a bit about showing messages: MessageBox Class
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Loop through all files in folder

 
0
  #10
Jan 4th, 2009
Thanks, I'm done for now. Wasn't using right syntax for message box. Thanks for all your help.

c ya tomorrow!!!
Regards,
Ali

Originally Posted by Antenka View Post
When you call GetFiles method, it return to you an array of strings (filenames). To show them in the message, you should organize them in way, that you like into a string. After that you can see here a bit about showing messages: MessageBox Class
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC