Search code examples
c++pdfdocx

Check that current file is doc, docx, xls, xlsx or pdf format


How i can check that current file is doc, docx, xls, xlsx or pdf format? What's a c++ library i can use for this goal in my C++ application?


Solution

  • If you want to understand file's type based on its contents, you can check the file's binary signature.


    If you want just to check the extension, you have 2 nice options:

    1. Use std::string functions find, find_first_of, find_last_of and substr to write your own logic that analyzes the file name.

    2. Use boost filesystem library's function extension.