I have this snippet of code below, were I am processing a list of files and moving them to a destination folder.
I already have a specific check in here for a file that is being copied to the network which I want to keep.
Is there anyway I could add another specific check in here that if a file is locked that I can ignore it and move onto the next one and continue on with the processing of the files?
public List<string> ProcessFiles()
{
string[] fileEntries = Directory.GetFiles(this.SourceLocation);
List<string> processedFiles = new List<string>();
foreach (string sourceFile in fileEntries)
{
//Verify the destination path exists and attempt move
if (Directory.Exists(destinationPath))
{
try
{
//Move the file to destination
File.Move(sourceFile, destinationFile);
}
catch(System.InvalidOperationException io)
{
//File is still being copied to the network, wait and try again
System.Threading.Thread.Sleep(500);
File.Move(sourceFile, destinationFile);
}
processedFiles.Add(fileNameNoPath);
}
}
return processedFiles;
}