I have a simple program. It runs .NET 4.5 and is built in Visual Studio 2013.
D:\\MyDir
is full of .xlsx
files and no .xls
files. When I run the program on Windows 8.1 x64, the filter for *.xls
returns no results. When I run the same program, with the same .NET version on Windows 7 x86, the *.xls
filter returns the same results as the *.xlsx
filter.
The test folders on both systems definitely contain the same data.
Am I missing something, or is this a bug in .NET and/or Windows?
The respective code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace throw_test
{
static class Program
{
static void Main()
{
int fileCount1 = Directory.GetFiles("D:\\MyDir", "*.xlsx").Length;
int fileCount2 = Directory.GetFiles("D:\\MyDir", "*.xls").Length;
Console.WriteLine("File Count 1: " + fileCount1);
Console.WriteLine("File Count 2: " + fileCount2);
Console.Read();
}
}
}
Edit 1
When I navigate to the directory using the command prompt in Windows 8.1 x64:
dir *.xlsx
returns all files as expecteddir *.xls
returns 'File Not Found'Windows 7 returns the expected files on both of the above commands.
My guess is that .NET uses this command under the hood, thus the above results?
GetFiles(String, String, SearchOption) Returns the names of files (including their paths) that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories.
[ VB.NET ] Net Framework will probably have Directory. getFiles method that supports multiple filters.
I tried on my machine with *.xls
and all xlsx
files are returned, just as described by MDSN.
I have Visual Studio 2013, built as Debug/Release Any CPU on .NET 4.5, and run on Win 8.1 X64 against NTFS/FAT32 partition, should cover your environment. Do you have anything else special?
EDIT
According to this question, you may have disabled 8.3 naming on your Win 8.1 System by running:
fsutil behavior set disable8dot3
You can query the current status by running
fsutil behavior query disable8dot3 <VolumePath>
On my machine it returns default setting like:
The volume state is: 0 (8dot3 name creation is enabled).
The registry state is: 2 (Per volume setting - the default).Based on the above two settings, 8dot3 name creation is enabled on c:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With