file.ToLower().Contains("setupv8.exe")
usually works fine. (though you might want to consider EndsWith instead)
Also, since EnumerateFiles
returns FileInfo
, you might as well check its Name
property instead:
foreach (FileInfo file in directory.EnumerateFiles((AppDomain.CurrentDomain.BaseDirectory),
"*.exe", SearchOption.AllDirectories))
{
if (!file.Name.ToLower().Contains("setupv8.exe")
{
// Do something with file
}
}
Also, if the name is "SetupV8.exe" and you don't expect it to be prefixed/suffixed with anything, perhaps just straight up check for equality at this point.
EDIT: Perhaps more importantly, you probably want to use just the file name. Unless you want to check if any part of the directory path matches. That is, you might not want c:\temp\setupv8.exe_directory\subdirectory\setupv8.exe
to match as a false positive.
EDIT 8 years later for new readers: There are some edge cases where using ToLower()
can introduce some unexpected results, so perhaps it might be preferable to use ToLowerInvariant()
instead.