C # Directory.GetFiles returns another result on another computer

In my application, I noticed a very strange thing. I have a piece of code that checks if a folder or any auxiliary folder contains .xlsfiles instead .xlsx. This is due to what I use EPPlus, which cannot process files .xls. On a computer that is running Windows 10 Home, the code below returns only files .xls, but not files .xlsx. Now I tried to run the same code on the machine Windows 10 Proas well using code .xlsx. I know that I can only get .xlsfiles using Linq, but I still would like to know why this could 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}");
}
+4
source share
1 answer

From MSDN

When you use an asterisk wildcard character in searchPattern, such as "* .txt", the number of characters in the specified extension affects the search as follows:

  • If the specified extension has exactly three characters, the method returns files with extensions that begin with the specified extension. For example, "*. Xls" returns both "book.xls" and
    "book.xlsx" .
  • In all other cases, the method returns files that exactly match the specified extension. For example, "* .ai" returns "file.ai" but not "file.aif".

, . , "file1.txt" "file1.txtother" "file?.txt" , "file *.txt" .

, MSDN.

8.3 filename. , , .

fsutil behavior set disable8dot3

+3

Source: https://habr.com/ru/post/1675488/


All Articles