gpt4 book ai didi

c# - 如何从文件路径名中提取文件名?

转载 作者:IT王子 更新时间:2023-10-29 04:17:16 25 4
gpt4 key购买 nike

我需要将所有文件从源文件夹移动到目标文件夹。如何从文件路径名中轻松提取文件名?

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);
}

最佳答案

尝试以下操作:

string newPathForFile = Path.Combine(newPath, Path.GetFileName(filePath));

关于c# - 如何从文件路径名中提取文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3986503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com