FileDetect
Table of Contents
Installation
pip install filedetect
Description
filedetect is a Python package that provides a simple way to detect file formats in a directory tree.
This project relies on the pathlib library to traverse the directory tree and separate files suffixes from their full name.
One can specify the suffixes to detect, the maximum depth of detection, and the formats to look for.
For convinence, some common suffixes are already defined for the following formats:
- video => {".mp4", ".mkv", ".avi", ".mov", ".wmv", ".flv", ".webm", ".m4v", ".mpeg", ".mpg", ".3gp", ".3g2", ".vob", ".ts", ".m2ts", ".rmvb", ".mxf", ".drc", ".amv", ".f4v", ".svi", ".m1v", ".m2v"}
- audio => {".mp3", ".wav", ".flac", ".aac", ".ogg", ".wma", ".m4a", ".opus", ".alac", ".aiff"}
- image => {".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".webp", ".svg", ".heif", ".raw"}
- plain_text => {".txt"}
- csv => {".csv"}
- json => {".json"}
- html => {".html", ".htm"}
- xml => {".xml"}
- excel => {".xls", ".xlsx", ".odf", ".ods"}
- pdf => {".pdf"}
- doc => {".doc", ".docx", ".odt"}
- ppt => {".ppt", ".pptx", ".odp"}
- archive => {".zip", ".tar", ".gz", ".bz2", ".xz", ".7z", ".rar", ".tar.gz", ".tar.bz2", ".tar.xz"}
- text => {".txt", ".csv", ".json", ".xml", ".html", ".htm", ".py", ".java", ".c", ".cpp", ".h", ".js", ".css", ".md", ".rst", ".tex", ".sql", ".css", ".yaml", ".yml", ".toml", ".ini", ".properties", ".log"}
But you can also specify your own suffixes to detect by passing a set of suffixes to the suffixes parameter instead of the format parameter.
And you also are welcome to suggest new formats to be added to the package or existing formats to be updated by creating a pull request or an issue on the GitHub repository !
Usage
CLI
filedetect [-h] [--list_formats] [--version] path [--format {video,image,audio,plain_text,csv,json,html,xml,excel,pdf,doc,ppt,archive,text,all,}] [--deep int] [--only_stems stem1,stem2] [--suffixes sfx1,sfx2]
-
The
pathargument is required and should be the path to the directory you want to scan. -
You can either specify the
--formator the--suffixesto detect, but not both at the same time. If both aren't specified, all formats will be detected. -
The
--only_stemsoption allows you to specify a set of stems to detect to filter for but is optional. -
The
--deepoption allows you to specify the maximum depth of detection. If not specified, the default value is -1, which means unlimited depth. -
The
--list_formatsoption allows you to list all the formats available in the package and their corresponding suffixes and exits. -
The
--versionoption allows you to display the version of the package and exits. -
The
--helpoption allows you to display the help message and exits."
Python
from filedetect import FileDetect
detector = FileDetect.find(
path="path/to/dir",
format=None, # ["video", "audio", "image", "text", "csv"; "json", "html"] | None for all formats
deep=-1, # positive int for maximum depth of detection or -1 for unlimited
only_stems=None, # None | a set of stems to detect,
suffixes=None, # None | a set of suffixes to detect (in place of format),
)
print(detector.result)
or
from filedetect import FileDetect
detector = FileDetect(
format=None, # ["video", "audio", "image", "text", "csv"; "json", "html"] | None for all formats
deep=-1, # positive int for maximum depth of detection or -1 for unlimited
only_stems=None, # None | a set of stems to detect,
suffixes=None, # None | a set of suffixes to detect (in place of format),
)
detector.run(
path="path/to/dir",
)
detector.run(
path="another/path/to/dir",
)
...
print(detector.result)
License
filedect is distributed under the terms of the AGPLv3 license.
Metadata
Release files for filedetect 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| filedetect-0.1.7.tar.gz | 20.0 kB | Without provenance | Details for filedetect-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| filedetect-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for filedetect-0.1.7-py3-none-any.whl |
Total release size: 38.6 kB
Release files / filedetect-0.1.7.tar.gz
| Download URL | filedetect-0.1.7.tar.gz |
|---|---|
| Size | 20.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
45fe626bc9776029638561f07eac3fcbb51529016936a7c17b04d548538a3bdb
|
|
BLAKE2b-256 checksum How to use checksums |
d5b62677fe89998477c03381561cfd44356bb588830f4846492acff2b083180c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Release files / filedetect-0.1.7-py3-none-any.whl
| Download URL | filedetect-0.1.7-py3-none-any.whl |
|---|---|
| Size | 18.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f96c8a3c1befaa8c5eb2985652dcc3fb91e258e7ba438b4d764d7d42b41c486c
|
|
BLAKE2b-256 checksum How to use checksums |
e65b9cedc601ca3a67a9e3e3018c8e9d5edab5c2992935842cbc6e4e4f54a5d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Security for filedetect 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.