Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
In my code
string temp = @"E:\";
string[] files = Directory.GetFiles(temp, "*.jpg", SearchOption.AllDirectories);
foreach (string file in files)
{
  filename = System.IO.Path.GetFileName(file);
  destFile = System.IO.Path.Combine(targetPath, filename);
  System.IO.File.Copy(file, destFile, true);
}
while running time ,i am not getting any files and foreach loop is not executing.
 
is there any other method for get all the folders in E drive that contains .jpg images.
Posted 1-Jan-13 23:28pm
josh-jw11.6K
Edited 1-Jan-13 23:56pm
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You can do as the following
 
var files = Directory.EnumerateFiles("C:\\path", "*.*", SearchOption.AllDirectories)
            .Where(s => s.EndsWith(".mp3") || s.EndsWith(".jpg"));
 
Please read Christoffer's answer here http://stackoverflow.com/questions/163162/can-you-call-directory-getfiles-with-multiple-filters[^]
 
It may help you .
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Is there an e drive ? Are there jpgs in it ? Have you stepped through in the debugger ?
  Permalink  
Comments
joshi.ihsoj at 2-Jan-13 4:36am
   
yes.there is E drive and there are imgaes in different folders.yes i stepped through debugger ,when debugging getfile method,the project is running and not going to next file for debugg.
Christian Graus at 2-Jan-13 4:37am
   
You mean there's an array of strings and it does not step through them ? Or you mean the list is empty ? If it's empty, then there's an issue in your code. They are named jpg, not jpeg ?
joshi.ihsoj at 2-Jan-13 4:38am
   
if i give
string temp = @"E:\SamplePictures";
as path then i will get the image path. but i want all the images from different folders in E drive
Christian Graus at 2-Jan-13 4:40am
   
I've never seen this variation, I'd use Directory.GetDirectories and write a recursive function.
joshi.ihsoj at 2-Jan-13 4:40am
   
debugging of getfile method is not completing.
joshi.ihsoj at 2-Jan-13 4:45am
   
if i use Directory.GetDirectories then also the same problem.
joshi.ihsoj at 2-Jan-13 4:47am
   
is it there any other method for get all the folders in E drive that contains .jpg images.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

using System.Security.Principal;
using System.IO;
 public ActionResult Index()
        {
            WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
            WindowsPrincipal currentPrincipal = new WindowsPrincipal(currentIdentity);
            if (currentPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
            {
                string temp = @"D:\", filename, destFile;
                string[] files = Directory.GetFiles(temp, "*.jpg", SearchOption.TopDirectoryOnly);
                foreach (string file in files)
                {
                    filename = System.IO.Path.GetFileName(file);
                    destFile = System.IO.Path.Combine(@"D:\Images", filename);
                    System.IO.File.Copy(file, destFile, true);
                }
            }
            return View("Index");
        }
  Permalink  
v2

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

  Print Answers RSS
0 Dnyaneshwar@Pune 719
1 Sergey Alexandrovich Kryukov 305
2 Peter Leow 280
3 TheRealSteveJudge 248
4 CPallini 195
0 Sergey Alexandrovich Kryukov 8,963
1 OriginalGriff 6,766
2 Peter Leow 4,262
3 Zoltán Zörgő 3,769
4 Richard MacCutchan 2,588


Advertise | Privacy | Mobile
Web01 | 2.8.150123.1 | Last Updated 24 Oct 2014
Copyright © CodeProject, 1999-2015
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