Case sensitive Directory.Exists / File.Exists

theknut picture theknut · Apr 24, 2013 · Viewed 18.9k times · Source

Is there a way to have a case sensitive Directory.Exists / File.Existssince

Directory.Exists(folderPath)

and

Directory.Exists(folderPath.ToLower())

both return true?

Most of the time it doesn't matter but I'm using a macro which seems not to work if the path doesn't match cases 100%.

Answer

Jacob Seleznev picture Jacob Seleznev · Apr 24, 2013

Since Directory.Exists uses FindFirstFile which is not case-sensitive, no. But you can PInvoke FindFirstFileEx with an additionalFlags parameter set to FIND_FIRST_EX_CASE_SENSITIVE