如何提取文件路径名文件名? [英] How to extract file name from file path name?
本文介绍了如何提取文件路径名文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从源文件夹中的所有文件移动到目标文件夹。我怎么能轻易地从文件路径名中提取文件名?
字符串的新路径=C:\\的新路径;
字符串[]文件路径= Directory.GetFiles(_configSection.ImportFilePath);
的foreach(在文件路径字符串文件路径)
{
//提取文件名,并添加新路径
File.Delete(文件路径);
}
解决方案
请尝试以下操作:
字符串newPathForFile = Path.Combine(的新路径,Path.GetFileName(文件路径));
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";
string[] filePaths = Directory.GetFiles(_configSection.ImportFilePath);
foreach (string filePath in filePaths)
{
// extract file name and add new path
File.Delete(filePath);
}
解决方案
Try the following:
string newPathForFile = Path.Combine(newPath, Path.GetFileName(filePath));
这篇关于如何提取文件路径名文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文