Specify File Type for Comparison Manually
Leave feedback
On this page
GroupDocs.Comparison for Python via .NET detects file type from the extension by default. When the extension is missing, wrong, or ambiguous, set the file type explicitly via LoadOptions.file_type.
from groupdocs.comparison import Comparer
from groupdocs.comparison.options import LoadOptions
from groupdocs.comparison.result import FileType
def specify_file_type_manually():
load_options = LoadOptions()
load_options.file_type = FileType.DOCX
with Comparer("./source.docx", load_options) as comparer:
comparer.add("./target.docx", load_options)
comparer.compare("./result.docx")
if __name__ == "__main__":
specify_file_type_manually()
source.docx is the source file used in this example. Click here to download it.
target.docx is the target file used in this example. Click here to download it.
Binary file (DOCX, 25 KB)
Use case: process files with incorrect or missing extensions by forcing the correct type.
A few commonly-used members of groupdocs.comparison.result.FileType:
| Format family | FileType value |
|---|---|
| Word | FileType.DOCX, FileType.DOC, FileType.DOT, FileType.DOTX, FileType.ODT, FileType.RTF |
FileType.PDF | |
| Spreadsheet | FileType.XLSX, FileType.XLS, FileType.ODS, FileType.CSV |
| Presentation | FileType.PPTX, FileType.PPT, FileType.ODP |
FileType.EML, FileType.MSG, FileType.EMLX | |
| Image | FileType.PNG, FileType.JPG, FileType.BMP, FileType.TIFF, FileType.GIF |
| Web | FileType.HTML, FileType.MHTML |
| Markdown | FileType.MD, FileType.MARKDOWN |
| Text & code | FileType.TXT, FileType.JSON, FileType.XML, FileType.YAML, FileType.PY, FileType.JS, FileType.CS, … |
To enumerate every supported value at runtime, call FileType.get_supported_file_types().
- Files with no extension. Documents downloaded from S3 or content systems that strip extensions still need a file-type hint.
- Wrong extension. Files renamed by content-management systems (e.g.,
.bin,.dat) that hold valid Word / PDF bytes. - Custom content-type detection. Pipelines where Python has already inspected the file (via
python-magicor similar) and wants to bypass the library’s extension-based detection.
- Get supported file formats — enumerate every recognised type at runtime.
- Load file from stream — streams have no implicit extension; combine with manual file-type for full control.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.