0
我想根据名称将文件从一个文件夹移动到另一个文件夹。 我想实现的是,我只从我的导出文件夹中选择这些特定的文件,并将其替换到我的目标文件夹中。目标文件夹中的项目是关键,所以我只需要这些文件,否则如果文件已存在于目标文件夹中,请将其替换。根据名称使用C#移动和替换文件
private static void CopyPaste()
{
var pstFileFolder = "C:/Users/chnikos/Desktop/CopyFolderTest/";
var searchPattern = "*.docx";
var soruceFolder= "C:/Users/chnikos/Desktop/CopyFolderTest/Test/";
// Searches the directory for *.pst
foreach (var file in Directory.GetFiles(pstFileFolder, searchPattern))
{
// Exposes file information like Name
var theFileInfo = new FileInfo(file);
// Gets the user name based on file name
// Sets up the destination location
var destination = soruceFolder+ theFileInfo.Name;
File.Move(file, destination);
}
}
源目标是:soruceFolder产地是:pstFileFolder
,我面对的是,我无法控制复制看来我的代码是获取所有文件,而不是问题检查是否在sourfolder这些文件存在
您能描述一下您使用此代码时遇到的问题吗?尤其是。目前还不清楚目标目标和源目标是什么 – Steve
在你的问题中没有问题!你能解释你有什么问题吗? –
你可能想阅读[如何调试小程序](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) –