SoFunction
Updated on 2025-03-07

C# programming implementation to obtain file names of all files in a folder

This article describes the C# programming implementation to obtain the file names of all files in a folder. Share it for your reference, as follows:

Want to implement such a function: batch modify the file names of all jpg files in a directory, and add specific strings to their original basis.

I first store all the file names in a directory with the format jpg into an array, and then uniformly modify the array value to batch modify the file names of the jpg file.

The code is as follows:

using System;
using ;
namespace ConsoleApplication7
{
 /// <summary>
 /// Class1 summary description. /// </summary>
 class Class1
 {
 /// <summary>
 /// The main entry point of the application. /// </summary>
 [STAThread]
 static void Main(string[] args)
 {
  string dirp=@"d:\\d";
  DirectoryInfo mydir = new DirectoryInfo(dirp);
  foreach (FileSystemInfo fsi in ())
  {
  if (fsi is FileInfo)
  {
    FileInfo fi = (FileInfo)fsi;
    string x=();
    (x);
    string s=();
    string y=();
    (y);
    if(s==".jpg")
    {
      (,x+@"\oo"+); //Prepare OO before the original file name      ();
    }
  }
  }
  ("success");
  ();
 }
 }
}

I hope this article will be helpful to everyone's C# programming.