Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my code
C#
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
Updated 1-Jan-13 22:56pm
v4

You can do as the following

C#
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 .
 
Share this answer
 
Is there an e drive ? Are there jpgs in it ? Have you stepped through in the debugger ?
 
Share this answer
 
Comments
josh-jw 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 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 ?
josh-jw 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 2-Jan-13 4:40am    
I've never seen this variation, I'd use Directory.GetDirectories and write a recursive function.
josh-jw 2-Jan-13 4:40am    
debugging of getfile method is not completing.
C#
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");
        }
 
Share this answer
 
v2

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