【发布时间】:2018-06-09 17:42:43
【问题描述】:
我正在尝试从路径中获取最新文件并将其复制,然后将其粘贴到生成的文件夹中。
这是我迄今为止尝试过的:
// This Method is called if the function/method CopyContent is invoked by the user or a bound event.
// Return true, if this component has to be revalidated!
public bool OnCopyContent(int arg)
{
// Get latet file from the specificed Folder
var directory = new DirectoryInfo(@""+sourceFolderPath);
var myFile = (from f in directory.GetFiles()
orderby f.LastWriteTime descending
select f).First();
// Newly Created Folder Name
string generatedFolderName = destinationFolderName;
// Newly Creted Folder Path (i.e C://Users/Desktop) Cretge it on desktop with name "Paste me here "
string generatedPathString = System.IO.Path.Combine(destinationFolderPath, generatedFolderName);
if (!File.Exists(generatedPathString))
System.IO.Directory.CreateDirectory(generatedPathString);
// Copy the Latet file to the newly Created Folder on the Desktop
string destFile = Path.Combine(@""+destinationFolderPath, myFile.Name);
File.Copy(myFile.FullName, destFile, true);
return false;
}
我想做的是
1:我有指定的文件夹路径,我想根据时间复制它的最新文件
2:在桌面上创建名为“NewlyAdded”的新文件夹
3:将复制的文件从指定文件夹粘贴到新建的文件夹中
【问题讨论】:
-
您的问题到底是什么?您的代码一目了然 - 您遇到了什么错误或出了什么问题?