I tried to use getfiles("*.jpeg) to get all the jpeg files form the dir. its not work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • david prince
    New Member
    • Jan 2011
    • 1

    #1

    I tried to use getfiles("*.jpeg) to get all the jpeg files form the dir. its not work

    Code:
    string path = "c:\\jpeg";
                
                long fileSize=0;
    
                DirectoryInfo dir = new DirectoryInfo(path);
    
                FileInfo[] fi = dir.GetFiles("*.jpeg");
                
                
    
                foreach (FileInfo jpegfile in fi)
                {
                    fileSize += fi.Length;
                   
                }
               
                MessageBox.Show("Size of JPEG file is:" + fileSize);
    Last edited by Curtis Rutland; Jan 7 '11, 10:36 PM.
  • Subin Ninan
    New Member
    • Sep 2010
    • 91

    #2
    Change *.jpeg to *.jpg

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      JPEG-format files are (VERY) rarely saved with an actual .jpeg extension, it's usually the shorter, abbreviated .jpg. Subin's reply is exactly what you need to do, mine is simply to tell you why, so you learn why it didn't work.

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        The best solution is to search for both.

        Code:
        FileInfo[] jpgs = di.GetFiles("*.jpg");
        FileInfo[] jpegs = di.GetFiles("*.jpeg");
        FileInfo[] allFiles = jpgs.Concat(jpegs).ToArray();

        Comment

        Working...