fileutils-dir 0.1.3__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fileutils/files.py +29 -25
- fileutils_dir-0.2.0.dist-info/METADATA +70 -0
- fileutils_dir-0.2.0.dist-info/RECORD +6 -0
- fileutils_dir-0.1.3.dist-info/METADATA +0 -59
- fileutils_dir-0.1.3.dist-info/RECORD +0 -6
- {fileutils_dir-0.1.3.dist-info → fileutils_dir-0.2.0.dist-info}/WHEEL +0 -0
- {fileutils_dir-0.1.3.dist-info → fileutils_dir-0.2.0.dist-info}/top_level.txt +0 -0
fileutils/files.py
CHANGED
|
@@ -2,23 +2,26 @@ from collections.abc import Iterable
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
|
|
4
4
|
FILE_TYPES = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
"image": [".jpg", ".jpeg", ".png", ".webp", ".bmp", ".gif", ".tiff"],
|
|
6
|
+
"text": [".txt", ".md", ".rst", ".log"],
|
|
7
|
+
"pdf": [".pdf"],
|
|
8
|
+
"doc": [".doc", ".docx", ".odt"],
|
|
9
|
+
"sheet": [".xls", ".xlsx", ".ods", ".csv"],
|
|
10
|
+
"presentation": [".ppt", ".pptx", ".odp"],
|
|
11
|
+
"code": [".py", ".js", ".ts", ".java", ".c", ".cpp", ".h", ".go", ".rs", ".rb", ".php", ".sh"],
|
|
12
|
+
"data": [".json", ".yaml", ".yml", ".xml", ".toml"],
|
|
13
|
+
"audio": [".mp3", ".wav", ".flac", ".ogg", ".aac", ".m4a"],
|
|
14
|
+
"video": [".mp4", ".mkv", ".avi", ".mov", ".webm"],
|
|
15
|
+
"archive": [".zip", ".tar", ".gz", ".bz2", ".7z", ".rar"],
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
|
|
16
18
|
def in_dir(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
path: str | Path = ".",
|
|
20
|
+
*,
|
|
21
|
+
ext: Iterable[str] | None = None,
|
|
22
|
+
dtype: Iterable[str] | None = None,
|
|
20
23
|
) -> list[str]:
|
|
21
|
-
|
|
24
|
+
|
|
22
25
|
ext = ext or []
|
|
23
26
|
dtype = dtype or []
|
|
24
27
|
|
|
@@ -29,19 +32,20 @@ def in_dir(
|
|
|
29
32
|
|
|
30
33
|
for file_type in dtype:
|
|
31
34
|
key = file_type.strip().lower()
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
if key not in FILE_TYPES:
|
|
36
|
+
raise ValueError(
|
|
37
|
+
f"Unknown file type: {file_type}. "
|
|
38
|
+
f"Valid types: {', '.join(FILE_TYPES)}"
|
|
39
|
+
)
|
|
40
|
+
normalized_extensions.update(FILE_TYPES[key])
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
files: list[str] = []
|
|
38
43
|
|
|
39
|
-
for
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
for item in Path(path).iterdir():
|
|
45
|
+
if item.is_file() and (
|
|
46
|
+
not normalized_extensions or item.suffix.lower() in normalized_extensions
|
|
47
|
+
):
|
|
48
|
+
files.append(str(item))
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
files_to_return.append(str(item))
|
|
50
|
+
return files
|
|
46
51
|
|
|
47
|
-
return files_to_return
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fileutils-dir
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Small utilities for listing files in directories
|
|
5
|
+
Author: Jatavallabhula Sarat Anirudh
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# fileutils
|
|
11
|
+
|
|
12
|
+
A small Python library for filtering and listing files.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install fileutils-dir
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from fileutils import in_dir
|
|
24
|
+
|
|
25
|
+
# List all files in the current directory
|
|
26
|
+
files = in_dir()
|
|
27
|
+
|
|
28
|
+
# Filter by extension
|
|
29
|
+
python_files = in_dir(ext=[".py"])
|
|
30
|
+
|
|
31
|
+
# Filter by predefined categories
|
|
32
|
+
media_files = in_dir(dtype=["image", "video"])
|
|
33
|
+
|
|
34
|
+
# Filter by both
|
|
35
|
+
results = in_dir(path="src", ext=[".c"], dtype=["text"])
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API Reference
|
|
39
|
+
|
|
40
|
+
### `in_dir(path=".", *, ext=None, dtype=None)`
|
|
41
|
+
|
|
42
|
+
Returns a list of file paths as strings from the specified directory.
|
|
43
|
+
|
|
44
|
+
- **path**: Directory to search. Accepts `str` or `pathlib.Path`. Defaults to `"."`.
|
|
45
|
+
- **ext**: An iterable of file extensions to include.
|
|
46
|
+
- **dtype**: An iterable of predefined file type categories.
|
|
47
|
+
|
|
48
|
+
If neither `ext` nor `dtype` are provided, all files in the directory are returned. If both are provided, the result is the union of both filters. Subdirectories are ignored.
|
|
49
|
+
|
|
50
|
+
## Supported Types
|
|
51
|
+
|
|
52
|
+
The `dtype` parameter supports the following categories:
|
|
53
|
+
|
|
54
|
+
| Category | Extensions |
|
|
55
|
+
| :--- | :--- |
|
|
56
|
+
| `image` | .jpg, .jpeg, .png, .webp, .bmp, .gif, .tiff |
|
|
57
|
+
| `text` | .txt, .md, .rst, .log |
|
|
58
|
+
| `pdf` | .pdf |
|
|
59
|
+
| `doc` | .doc, .docx, .odt |
|
|
60
|
+
| `sheet` | .xls, .xlsx, .ods, .csv |
|
|
61
|
+
| `presentation` | .ppt, .pptx, .odp |
|
|
62
|
+
| `code` | .py, .js, .ts, .java, .c, .cpp, .h, .go, .rs, .rb, .php, .sh |
|
|
63
|
+
| `data` | .json, .yaml, .yml, .xml, .toml |
|
|
64
|
+
| `audio` | .mp3, .wav, .flac, .ogg, .aac, .m4a |
|
|
65
|
+
| `video` | .mp4, .mkv, .avi, .mov, .webm |
|
|
66
|
+
| `archive` | .zip, .tar, .gz, .bz2, .7z, .rar |
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
fileutils/__init__.py,sha256=3u-pHKVodcCPECMcj95lrkk8nr7tl6_HRqiQOw6YbBM,78
|
|
2
|
+
fileutils/files.py,sha256=yi3BJ2LjMjZj2HrsYdg8DcbVnC_YLpeNU36zFuQeRlI,1608
|
|
3
|
+
fileutils_dir-0.2.0.dist-info/METADATA,sha256=gXU9cdAsHvui4688zANbbIhETbGln9w2U0aqyC87mvc,1899
|
|
4
|
+
fileutils_dir-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
5
|
+
fileutils_dir-0.2.0.dist-info/top_level.txt,sha256=kZPCAZpYo7OkmwY_R2a4ifuMINdW5AZd2JaNHDSXQYQ,10
|
|
6
|
+
fileutils_dir-0.2.0.dist-info/RECORD,,
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: fileutils-dir
|
|
3
|
-
Version: 0.1.3
|
|
4
|
-
Summary: Small utilities for listing files in directories
|
|
5
|
-
Author: Jatavallabhula Sarat Anirudh
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Requires-Python: >=3.9
|
|
8
|
-
Description-Content-Type: text/markdown
|
|
9
|
-
|
|
10
|
-
# fileutils
|
|
11
|
-
|
|
12
|
-
Small utilities for working with files and directories.
|
|
13
|
-
|
|
14
|
-
Currently provides a helper to list files in one or more directories,
|
|
15
|
-
optionally filtered by file extension or file type.
|
|
16
|
-
|
|
17
|
-
Installation (local development)
|
|
18
|
-
|
|
19
|
-
pip install -e .
|
|
20
|
-
|
|
21
|
-
Usage
|
|
22
|
-
|
|
23
|
-
from fileutils import in_dir
|
|
24
|
-
|
|
25
|
-
# All files in current directory
|
|
26
|
-
files = in_dir()
|
|
27
|
-
|
|
28
|
-
# All Python files
|
|
29
|
-
files = in_dir(extensions=[".py"])
|
|
30
|
-
|
|
31
|
-
# Files by type
|
|
32
|
-
files = in_dir(types=["code"])
|
|
33
|
-
|
|
34
|
-
# Multiple directories
|
|
35
|
-
files = in_dir(directories=["src", "tests"], types=["code"])
|
|
36
|
-
|
|
37
|
-
Behavior
|
|
38
|
-
|
|
39
|
-
- Defaults to the current directory (.)
|
|
40
|
-
- If no extensions or types are provided, all files are returned
|
|
41
|
-
- If both are provided, the result is the union of both filters
|
|
42
|
-
- Only files are returned (directories are ignored)
|
|
43
|
-
|
|
44
|
-
Supported types
|
|
45
|
-
|
|
46
|
-
Common file groups such as:
|
|
47
|
-
- code
|
|
48
|
-
- text
|
|
49
|
-
- image
|
|
50
|
-
- pdf
|
|
51
|
-
- audio
|
|
52
|
-
- video
|
|
53
|
-
- archive
|
|
54
|
-
|
|
55
|
-
See source for the full mapping.
|
|
56
|
-
|
|
57
|
-
License
|
|
58
|
-
|
|
59
|
-
MIT
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
fileutils/__init__.py,sha256=3u-pHKVodcCPECMcj95lrkk8nr7tl6_HRqiQOw6YbBM,78
|
|
2
|
-
fileutils/files.py,sha256=pSHHNR8oZyCtSi7ZL73wIqywyntwe7mKVogaAdhLh_8,1718
|
|
3
|
-
fileutils_dir-0.1.3.dist-info/METADATA,sha256=f4HpV1wJjFH_7pcDiCqP0Yd8Mo6ArSNKvXLWLJg4v8M,1239
|
|
4
|
-
fileutils_dir-0.1.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
5
|
-
fileutils_dir-0.1.3.dist-info/top_level.txt,sha256=kZPCAZpYo7OkmwY_R2a4ifuMINdW5AZd2JaNHDSXQYQ,10
|
|
6
|
-
fileutils_dir-0.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|