I just noticed a very weird thing in my application. I have a snippet of code that checks if a folder or any sub folder contains .xls
files instead of .xlsx
. This is because I use EPPlus
which can't handle .xls
files. On a computer running Windows 10 Home
the code below only returns .xls
files but not any .xlsx
files. I now tried to run the same code on a Windows 10 Pro
machine and the code picked up .xlsx
files as well. I know I can get only .xls
files using Linq
but I still would like to know why this can happen.
var filePaths = Directory.GetFiles("C:\\xmlfiles", "*.xls", SearchOption.AllDirectories).ToList();
if (filePaths.Count > 0)
{
var files = string.Join(",", filePaths);
throw new Exception($"Folder contains .xls files which EPPlus can't handle. Please convert them first. Files: {files}");
}
From MSDN
When you use the asterisk wildcard character in a searchPattern such as "*.txt", the number of characters in the specified extension affects the search as follows:
When you use the question mark wildcard character, this method returns only files that match the specified file extension. For example, given two files, "file1.txt" and "file1.txtother", in a directory, a search pattern of "file?.txt" returns just the first file, whereas a search pattern of "file*.txt" returns both files.
Above is normal behaviour as MSDN says.
But on your question it may cause from filename convention 8.3 filename . Disable it and look if you get the result as expected.
fsutil behavior set disable8dot3
Also take a look at this question
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.