How to get only filenames within a directory using c#?

后端 未结 7 1716
闹比i
闹比i 2020-12-04 15:05

When I use the line of code as below , I get an string array containing the entire path of the individual files .

private string[] pdfFiles = Directory.GetF         


        
7条回答
  •  生来不讨喜
    2020-12-04 15:42

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace GetNameOfFiles
    {
        public class Program
        {
            static void Main(string[] args)
            {
               string[] fileArray = Directory.GetFiles(@"YOUR PATH");
               for (int i = 0; i < fileArray.Length; i++)
               {
    
                   Console.WriteLine(fileArray[i]);
               }
                Console.ReadLine();
            }
        }
    }
    

提交回复
热议问题