Does .net have a way to determine whether the local filesystem is case-sensitive?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- Is shmid returned by shmget() unique across proces
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
You can create a file in the temp folder (using lowercase filename), then check if the file exists (using uppercase filename), e.g:
There is no such a function in the .NET Class Library.
You can, however, roll out your own: Try creating a file with a lowercase name and then try to open it with the upparcase version of its name. Probably it is possible to improve this method, but you get the idea.
EDIT: You could actually just take the first file in the root directory and then check if both filename.ToLower() and filename.ToUpper() exist. Unfortunately it is quite possible that both uppercase and lowercase variants of the same file exist, so you should compare the FileInfo.Name properties of both the lowercase and uppercase variants to see if they are indeed the same or not. This will not require writing to the disk.
Obviously, this will fail if there are no files at all on the volume. In this case, just fall back to the first option (see Martin's answer for the implementation).
Based on M4N's answer, with the following changes:
A better strategy would be to take a path as an argument, and create the file on the same filesystem, but writing there might have unexpected consequences.