fileutils-dir 0.1.3__tar.gz
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_dir-0.1.3/PKG-INFO +59 -0
- fileutils_dir-0.1.3/README.md +50 -0
- fileutils_dir-0.1.3/fileutils/__init__.py +5 -0
- fileutils_dir-0.1.3/fileutils/files.py +47 -0
- fileutils_dir-0.1.3/fileutils_dir.egg-info/PKG-INFO +59 -0
- fileutils_dir-0.1.3/fileutils_dir.egg-info/SOURCES.txt +8 -0
- fileutils_dir-0.1.3/fileutils_dir.egg-info/dependency_links.txt +1 -0
- fileutils_dir-0.1.3/fileutils_dir.egg-info/top_level.txt +1 -0
- fileutils_dir-0.1.3/pyproject.toml +14 -0
- fileutils_dir-0.1.3/setup.cfg +4 -0
|
@@ -0,0 +1,59 @@
|
|
|
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
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# fileutils
|
|
2
|
+
|
|
3
|
+
Small utilities for working with files and directories.
|
|
4
|
+
|
|
5
|
+
Currently provides a helper to list files in one or more directories,
|
|
6
|
+
optionally filtered by file extension or file type.
|
|
7
|
+
|
|
8
|
+
Installation (local development)
|
|
9
|
+
|
|
10
|
+
pip install -e .
|
|
11
|
+
|
|
12
|
+
Usage
|
|
13
|
+
|
|
14
|
+
from fileutils import in_dir
|
|
15
|
+
|
|
16
|
+
# All files in current directory
|
|
17
|
+
files = in_dir()
|
|
18
|
+
|
|
19
|
+
# All Python files
|
|
20
|
+
files = in_dir(extensions=[".py"])
|
|
21
|
+
|
|
22
|
+
# Files by type
|
|
23
|
+
files = in_dir(types=["code"])
|
|
24
|
+
|
|
25
|
+
# Multiple directories
|
|
26
|
+
files = in_dir(directories=["src", "tests"], types=["code"])
|
|
27
|
+
|
|
28
|
+
Behavior
|
|
29
|
+
|
|
30
|
+
- Defaults to the current directory (.)
|
|
31
|
+
- If no extensions or types are provided, all files are returned
|
|
32
|
+
- If both are provided, the result is the union of both filters
|
|
33
|
+
- Only files are returned (directories are ignored)
|
|
34
|
+
|
|
35
|
+
Supported types
|
|
36
|
+
|
|
37
|
+
Common file groups such as:
|
|
38
|
+
- code
|
|
39
|
+
- text
|
|
40
|
+
- image
|
|
41
|
+
- pdf
|
|
42
|
+
- audio
|
|
43
|
+
- video
|
|
44
|
+
- archive
|
|
45
|
+
|
|
46
|
+
See source for the full mapping.
|
|
47
|
+
|
|
48
|
+
License
|
|
49
|
+
|
|
50
|
+
MIT
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
FILE_TYPES = {
|
|
5
|
+
"image": [".jpg", ".jpeg", ".png", ".webp", ".bmp", ".gif", ".tiff"],
|
|
6
|
+
"text": [".txt", ".md", ".rst", ".log"], "pdf": [".pdf"], "doc": [".doc", ".docx", ".odt"],
|
|
7
|
+
"sheet": [".xls", ".xlsx", ".ods", ".csv"], "presentation": [".ppt", ".pptx", ".odp"],
|
|
8
|
+
"code": [".py", ".js", ".ts", ".java", ".c", ".cpp", ".h", ".go", ".rs", ".rb", ".php", ".sh"],
|
|
9
|
+
"data": [".json", ".yaml", ".yml", ".xml", ".toml"],
|
|
10
|
+
"audio": [".mp3", ".wav", ".flac", ".ogg", ".aac", ".m4a"],
|
|
11
|
+
"video": [".mp4", ".mkv", ".avi", ".mov", ".webm"],
|
|
12
|
+
"archive": [".zip", ".tar", ".gz", ".bz2", ".7z", ".rar"],
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def in_dir(
|
|
17
|
+
paths: Iterable[str] | None = None,
|
|
18
|
+
ext: Iterable[str] | None = None,
|
|
19
|
+
dtype: Iterable[str] | None = None,
|
|
20
|
+
) -> list[str]:
|
|
21
|
+
paths = paths or ["."]
|
|
22
|
+
ext = ext or []
|
|
23
|
+
dtype = dtype or []
|
|
24
|
+
|
|
25
|
+
normalized_extensions = {
|
|
26
|
+
e.lower() if e.startswith(".") else f".{e.lower()}"
|
|
27
|
+
for e in ext
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for file_type in dtype:
|
|
31
|
+
key = file_type.strip().lower()
|
|
32
|
+
try:
|
|
33
|
+
normalized_extensions.update(FILE_TYPES[key])
|
|
34
|
+
except KeyError:
|
|
35
|
+
raise ValueError(f"Unknown file type: {file_type}")
|
|
36
|
+
|
|
37
|
+
files_to_return: list[str] = []
|
|
38
|
+
|
|
39
|
+
for path in paths:
|
|
40
|
+
for item in Path(path).iterdir():
|
|
41
|
+
if not item.is_file():
|
|
42
|
+
continue
|
|
43
|
+
|
|
44
|
+
if not normalized_extensions or item.suffix.lower() in normalized_extensions:
|
|
45
|
+
files_to_return.append(str(item))
|
|
46
|
+
|
|
47
|
+
return files_to_return
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fileutils
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fileutils-dir"
|
|
3
|
+
version = "0.1.3"
|
|
4
|
+
description = "Small utilities for listing files in directories"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = [
|
|
9
|
+
{name = "Jatavallabhula Sarat Anirudh"}
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["setuptools"]
|
|
14
|
+
build-backend = "setuptools.build_meta"
|