Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net file pattern picks up unwanted files (C#)

Tags:

c#

.net

io

I have a command as below. I find if I use a file pattern of *.csv it also picks up items with a .csvx extension. Maybe it's a throwback to the 8.3 filename days - anyone know a way that would return them properly, preferably without rolling our own?

files = (from file in Directory.EnumerateFiles(sourceFolder, filePattern, SearchOption.TopDirectoryOnly) select file).ToList();
like image 516
Glinkot Avatar asked Jan 04 '12 22:01

Glinkot


1 Answers

Just a workaround but might be good enough:

var files = Directory
             .EnumerateFiles(sourceFolder, filePattern, SearchOption.TopDirectoryOnly)
             .Where(f => f.EndsWith(".csv"))
             .ToList();
like image 92
ChrisWue Avatar answered Sep 28 '22 08:09

ChrisWue