How to extract file name from file path name?

前端 未结 5 989
粉色の甜心
粉色の甜心 2020-12-20 11:09

I need to move all files from source folder to destination folder. How can I easily extract file name from file path name?

string newPath = \"C:\\\\NewPath\"         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 11:35

    You can do it like this:

    string newPath = "C:\\NewPath"; 
    string[] filePaths = Directory.GetFiles(_configSection.ImportFilePath);  
    foreach (string filePath in filePaths)  
    {  
       string newFilePath = Path.Combine(newPath, Path.GetFileName(filePath);
       File.Move(filePath, newFilePath);
    }
    

提交回复
热议问题