我想在电脑上的一个特定目录中,每当创建文件时,将文件从该目录剪切并粘贴到新目录中。我已经监视了该目录,那么像这样简单的事情是否可行:
if (e.ChangeType == System.IO.WatcherChangeTypes.Created)
{
//cut file
//paste into new directory
}
我想在电脑上的一个特定目录中,每当创建文件时,将文件从该目录剪切并粘贴到新目录中。我已经监视了该目录,那么像这样简单的事情是否可行:
if (e.ChangeType == System.IO.WatcherChangeTypes.Created)
{
//cut file
//paste into new directory
}
LockFileEx
。在获得文件的独占锁之前,您可能需要等待很长时间。相反,您应该将创建的文件排队以由辅助线程(或线程池)锁定和移动。 string sourceFilePath = @"Your Path , ex : C:\";
string destinationFilePath = @"Your Path , ex : C:\";
System.IO.File.Move(sourceFilePath, destinationFilePath);