PDA

View Full Version : Identifying file type in excel



jd.smithuk
07-28-2017, 12:55 PM
I have a directory with approx. 5000 files in it all with a suffix of .SRC some of these files are actually excel files while others are csv or txt I am quite happy to write the code to process the files one at a time but as anyone any idea how I can tell if a file is excel or not ?

Thanks for any help

John

Leith Ross
07-28-2017, 06:31 PM
Hello John,

Welcome to the forum! Since the days of MS-DOS, file systems have relied on the file extension to associate a file with its application. Changing the file extension was and still is a way to hide files.If the file extension is not associated with a application in the system registry, the system has no idea what to do with the file. You might be able to roll your code to identify an unknown file but it would be very difficult and time consuming.

Why were the extensions changed?

Paul_Hossler
07-28-2017, 06:50 PM
Write a macro that opens each SCR file and reads the first 2 bytes

If they're (50)(4B) in hex, (or "PK") then the file is most likely a xlsx (but could also be any Office OpenXML file)

If they're (0D(CF) in hex, then the file is most likely a xls


To find if it's a CSV, I guess you could read a line to a CrLf and count commas

More than 4, it's CSV otherwise it's TXT

Good luck