How to get image names inside a folder and move names to text file in c#

Advertisement
       In this article i am going to explain how to get image names inside a folder and move names to text file in c#.
             I am having 2000 images(.jpg) in image folder and want to get all the image names, that stores in one text file. The following code will help you to get all image names which stores in one text file.


string[] array1 = Directory.GetFiles(@"C:\Images\", "*.jpg");
            Console.WriteLine(array1.Count().ToString());
            int count = 1;
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Imgs.txt"))
            {
                foreach (string name in array1)
                {
                    string[] spltname = name.Split('\\');

                    Console.WriteLine(spltname[spltname.Length-1]);
                    file.WriteLine(count.ToString()+","+spltname[spltname.Length - 1]);
                    count++;
                }
            }
           
          
Advertisements
SHARE

Lakshmi Tulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a comment