Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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-jw9.6K
Comments
Sergey Alexandrovich Kryukov at 2-Jan-13 23:37pm
   
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 at 2-Jan-13 23:41pm
   
thnx chris.
joshi.ihsoj at 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 at 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 at 2-Jan-13 23:41pm
   
Thank you, Sergey
Sergey Alexandrovich Kryukov at 2-Jan-13 23:42pm
   
You are very welcome.
Good luck, call again.
—SA
joshi.ihsoj at 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 at 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)

  Print Answers RSS
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 330
2 ClimerChinna 222
3 OriginalGriff 206
4 Richard MacCutchan 170
0 Sergey Alexandrovich Kryukov 8,298
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,005
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
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