Given a filesystem path, is there a shorter way to extract the filename without its extension?

后端 未结 11 973
面向向阳花
面向向阳花 2020-11-22 09:31

I program in WPF C#. I have e.g. the following path:

C:\\Program Files\\hello.txt

and I want to extract hello

11条回答
  •  一整个雨季
    2020-11-22 10:00

    Namespace: using System.IO;  
     //use this to get file name dynamically 
     string filelocation = Properties.Settings.Default.Filelocation;
    //use this to get file name statically 
    //string filelocation = @"D:\FileDirectory\";
    string[] filesname = Directory.GetFiles(filelocation); //for multiple files
    
    Your path configuration in App.config file if you are going to get file name dynamically  -
    
        
            
              
                D:\\DeleteFileTest
              
                  
          
    

提交回复
热议问题