Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My system Drive E containing 3 folders.1)System volume 2)Pictures 3)Files.
here Pictures folder and file folder only containing images.
How to retrieve these two file names in c#.
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jan-13 23:37pm    
What's the problem, how to read MSDN?
—SA

System.IO.Directory.GetDirectories will get you directories. You'll need to use GetFiles to work out which ones have images.
 
Share this answer
 
Comments
josh-jw 2-Jan-13 23:41pm    
thnx chris.
josh-jw 3-Jan-13 0:04am    
In the same scenario
var filename= Directory.GetFiles(name,"*.*",SearchOption.AllDirectories).Where(file => Regex.IsMatch(file, @"^.+\.(wav|mp3|jpg)$"));

its not working.i am not getting any files like folder inside another folder.
Christian Graus 3-Jan-13 0:05am    
I am not sure that AllDirectories does what you hope it to do. I doubt it recurses. You still need to write a method to do that
The question is not quite clearly formulated, but you can use the method System.IO.Directory.GetFiles:
http://msdn.microsoft.com/en-us/library/system.io.directory.getfiles.aspx[^].

But this is something you need much more: Microsoft Q209354.

—SA
 
Share this answer
 
Comments
josh-jw 2-Jan-13 23:41pm    
Thank you, Sergey
Sergey Alexandrovich Kryukov 2-Jan-13 23:42pm    
You are very welcome.
Good luck, call again.
—SA
josh-jw 3-Jan-13 0:04am    
In the same scenario
var filename= Directory.GetFiles(name,"*.*",SearchOption.AllDirectories).Where(file => Regex.IsMatch(file, @"^.+\.(wav|mp3|jpg)$"));

its not working.i am not getting any files like folder inside another folder.
Sergey Alexandrovich Kryukov 3-Jan-13 0:50am    
Everything before Regex is correct, check "where" (what is "file"?). As a variant: call GetFiles 3 time for each of file type separately...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900