そのファイルのコピーを防ぐために、特定のファイルが開いているかどうかを確認する必要があります。
多くの例を試してみましたが、どれもうまくいきません! たとえば、これを試します:
protected virtual bool IsFileLocked(FileInfo file)
{
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
finally
{
if (stream != null)
stream.Close();
}
//file is not locked
return false;
}
オリエンテーションが必要です...どこで失敗しますか? 提案?