Search code examples
c#directorydrivegetfiles

DirectoryInfo.GetFiles with wildcard bahaves differently on C and D drive


I have an issue similar to the issue mention in the below link. .NET DirectoryInfo.GetFiles with wildcard bahaves differently on different drives

In a folder I have file with .xls and .xlsx extensions, when using DirectoryInfo.GetFiles("*.xls"), it returns files with both the extensions. This issue exist with files in C drive but in D drive there is no issue.

When I checked that state of C and D drive using fsutil behavior query Disable8dot3, the volume state in C dive is ENABLED and in D drive is DISABLED. Then I tried to DISABLE C drive using fsutil 8dot3name set C: 1. When disabling C drive, I expected that the issue will not occur for C drive but there is no difference in behavior.

I could not identify the actual root cause of this issue.


Solution

  • According to some of my tests, the documentation mentioned in my previous comment should be inaccurate, the problem is still mainly because GetFiles matches both long and 8.3 file names.

    Then I tried to DISABLE C drive using fsutil 8dot3name set C: 1. When disabling C drive, I expected that the issue will not occur for C drive but there is no difference in behavior.

    When you enable 8.3 file names on a volume, existing long file names will not automatically obtain their short names. Vice versa existing short names will not automatically disappear when the option is disabled. You can verify it by using DIR /X command.

    According to this question and my tests, only new created files on the file system will be affected by the 8dot3name option.