Click here to Skip to main content
12,354,998 members (66,083 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
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 2-Jan-13 17:25pm
josh-jw15.8K
Comments
   
What's the problem, how to read MSDN?
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

System.IO.Directory.GetDirectories will get you directories. You'll need to use GetFiles to work out which ones have images.
  Permalink  
Comments
joshi.ihsoj 2-Jan-13 23:41pm
   
thnx chris.
joshi.ihsoj 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
joshi.ihsoj 2-Jan-13 23:41pm
   
Thank you, Sergey
   
You are very welcome.
Good luck, call again.
—SA
joshi.ihsoj 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.
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100