I have this code:
bool containsNonAllowedCLEOFiles = directory.EnumerateFiles().Any(file => !allowedCLEOFiles.Contains(file.Name));
if (containsNonAllowedCLEOFiles == true)
{
DialogResult existsunallowedcleofiles = MessageBox.Show("Extraneous files found! Please remove them", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if(existsunallowedcleofiles == DialogResult.OK)
{
//move files
}
return;
}
If extraneous/unallowed files exist, I'm getting this message. But I want to move those files to another directory when I click OK. How can I do it? I want to move not all files, but only extraneous / unallowed.
P.S I know that I must use File.Move("file", "directory"); or something like this, but I don't know how to get that file name.. etc.
Try
foreach (var file in directory.EnumerateFiles().Where(file => !allowedCLEOFiles.Contains(file.Name)) {
File.Move(file.Name, destination);
}