2

Here's my problem: I have files that are being generated in pairs by third party software. The files have the exact same name and both have a file extension of .ACS - the only difference I can find is that one file type is recognized as an ACS file and the other is recognized as a CSV file. I need to get all of the ACS type files. Normally I would just use something like this:

string[] files = Directory.GetFiles("\\somedrive\location", "*.ACS");

My issue is that this picks up both files and I need to ignore the file that has a type of csv. So, how can this be done? Is there a way to expose the file type property?

(The ACS files can be opened in notepad if it helps...I'm just doing some basic data manipulation with them).

ovaltein
  • 1,185
  • 2
  • 12
  • 34
  • I would recommend working out if there is any kind of common file header information available for the ACS file types. If would mean you have to write code to loop all directory files manually and read the first few bytes though, and filter them that way – musefan Sep 24 '13 at 14:29
  • You'd have to open the file and look for some kind of fingerprint in the data. – asawyer Sep 24 '13 at 14:29

1 Answers1

2

You could look at the file itself, using urlmon.dll for example.

Check this out: http://www.pinvoke.net/default.aspx/urlmon.findmimefromdata

I'm doing this using code found here: Using .NET, how can you find the mime type of a file based on the file signature not the extension

Community
  • 1
  • 1
Mikael Östberg
  • 16,982
  • 6
  • 61
  • 79