detect_file_type method
Leave feedback
On this page
Detects the file type of the container item.
def detect_file_type(self, detection_mode):
...
| Parameter | Type | Description |
|---|---|---|
| detection_mode | FileTypeDetectionMode |
Defines a mode of the file type detection. |
Returns: An instance of FileType; FileType.unknown if a file type isn’t detected.
The detection_mode parameter provides the ability to control file type detection:
- Default – The file type is detected by the file extension; if the file extension isn’t recognized, the file type is detected by the file content.
- Extension – The file type is detected only by the file extension.
- Content – The file type is detected only by the file content.
from groupdocs.parser import Parser
from groupdocs.parser.options import FileTypeDetectionMode
def detect_items(file_path):
with Parser(file_path) as parser:
attachments = parser.get_container()
if not attachments:
print("Container extraction isn't supported")
return
for item in attachments:
file_type = item.detect_file_type(FileTypeDetectionMode.DEFAULT)
print(f"{item.name}: {file_type}")
- class
ContainerItem
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.