Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
there is a folder this folder has pictures jpeg format

how to read extensions one by one john.jpeg susan.jpeg xxx.jpeg names of pictures inside a folder?

so I need john.jpeg for example I want to take only john
Posted

Try Directory.GetFiles Method[^]
C#
string[] dirs = Directory.GetFiles(@"c:\", "*.jpeg");
 
Share this answer
 
You can Try the following C# Code

C#
public void GetFiles(string path)
        {

            if (File.Exists(path))
            {
                // This path is a file
                ProcessFile(path);
            }

            else if (Directory.Exists(path))
            {
            {
                // This path is a directory
                ProcessDirectory(path);
            }

        }

        public void ProcessDirectory(string targetDirectory)
        {
            // Process the list of files found in the directory.
            string[] fileEntries = Directory.GetFiles(targetDirectory);
            foreach (string fileName in fileEntries)
                ProcessFile(fileName);

            // Recurse into subdirectories of this directory.
            string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
            foreach (string subdirectory in subdirectoryEntries)

                ProcessDirectory(subdirectory);
        }

        public string ProcessFile(string path)
        {
            FileInfo fi = new FileInfo(path);
            string sExtension = fi.Extension;

            return sExtension;
        }
 
Share this answer
 
Comments
Member-2338430 15-May-13 6:56am    
thanks a lot

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