doFolder 2.2.2__tar.gz → 2.2.4__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.
- dofolder-2.2.4/PKG-INFO +256 -0
- dofolder-2.2.4/README.md +231 -0
- {dofolder-2.2.2 → dofolder-2.2.4}/pyproject.toml +5 -2
- dofolder-2.2.4/src/doFolder/__init__.py +104 -0
- dofolder-2.2.4/src/doFolder/__pkginfo__.py +11 -0
- dofolder-2.2.4/src/doFolder/compare.py +356 -0
- dofolder-2.2.4/src/doFolder/enums.py +87 -0
- dofolder-2.2.4/src/doFolder/exception.py +118 -0
- {dofolder-2.2.2 → dofolder-2.2.4}/src/doFolder/fileSystem.py +274 -259
- dofolder-2.2.4/src/doFolder/globalType.py +70 -0
- dofolder-2.2.4/src/doFolder/hashing.py +884 -0
- dofolder-2.2.4/src/doFolder.egg-info/PKG-INFO +256 -0
- {dofolder-2.2.2 → dofolder-2.2.4}/src/doFolder.egg-info/SOURCES.txt +2 -0
- dofolder-2.2.2/PKG-INFO +0 -65
- dofolder-2.2.2/README.md +0 -40
- dofolder-2.2.2/src/doFolder/__init__.py +0 -43
- dofolder-2.2.2/src/doFolder/compare.py +0 -265
- dofolder-2.2.2/src/doFolder/enums.py +0 -64
- dofolder-2.2.2/src/doFolder/exception.py +0 -97
- dofolder-2.2.2/src/doFolder/globalType.py +0 -57
- dofolder-2.2.2/src/doFolder.egg-info/PKG-INFO +0 -65
- {dofolder-2.2.2 → dofolder-2.2.4}/LICENSE +0 -0
- {dofolder-2.2.2 → dofolder-2.2.4}/setup.cfg +0 -0
- {dofolder-2.2.2 → dofolder-2.2.4}/src/doFolder/path.py +0 -0
- {dofolder-2.2.2 → dofolder-2.2.4}/src/doFolder.egg-info/dependency_links.txt +0 -0
- {dofolder-2.2.2 → dofolder-2.2.4}/src/doFolder.egg-info/requires.txt +0 -0
- {dofolder-2.2.2 → dofolder-2.2.4}/src/doFolder.egg-info/top_level.txt +0 -0
dofolder-2.2.4/PKG-INFO
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: doFolder
|
|
3
|
+
Version: 2.2.4
|
|
4
|
+
Summary: Manage files more easily
|
|
5
|
+
Author-email: kuankuan <2163826131@qq.com>
|
|
6
|
+
License-Expression: MulanPSL-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/kuankuan2007/do-folder
|
|
8
|
+
Project-URL: Issues, https://github.com/kuankuan2007/do-folder/issues
|
|
9
|
+
Project-URL: Documentation, https://do-folder.doc.kuankuan.site
|
|
10
|
+
Keywords: folder,file,manage,filesystem,directory
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: exceptiongroup
|
|
22
|
+
Requires-Dist: typing_extensions>=4.10.0
|
|
23
|
+
Requires-Dist: deprecated
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# doFolder
|
|
27
|
+
|
|
28
|
+
[](https://badge.fury.io/py/doFolder) [](https://github.com/kuankuan2007/do-folder)  [](./LICENSE) [](https://do-folder.doc.kuankuan.site)
|
|
29
|
+
|
|
30
|
+
**doFolder** is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.
|
|
31
|
+
|
|
32
|
+
## ✨ Key Features
|
|
33
|
+
|
|
34
|
+
- **🎯 Object-oriented Design**: Work with files and directories as Python objects
|
|
35
|
+
- **🌐 Cross-platform Compatibility**: Seamlessly works on Windows, macOS, and Linux
|
|
36
|
+
- **🛤️ Advanced Path Handling**: Built on Python's pathlib for robust path management
|
|
37
|
+
- **📁 Complete File Operations**: Create, move, copy, delete, and modify files and directories
|
|
38
|
+
- **📝 Content Management**: Read and write file content with encoding support
|
|
39
|
+
- **🌳 Directory Tree Operations**: Navigate and manipulate directory structures
|
|
40
|
+
- **🔍 File Comparison**: Compare files and directories with various comparison modes
|
|
41
|
+
- **🔒 Hash Support**: Generate and verify file hashes for integrity checking
|
|
42
|
+
- **⚠️ Flexible Error Handling**: Comprehensive error modes for different use cases
|
|
43
|
+
- **🏷️ Type Safety**: Full type hints for better IDE support and code reliability
|
|
44
|
+
|
|
45
|
+
## 📦 Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install doFolder
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Requirements:** Python 3.8+
|
|
52
|
+
|
|
53
|
+
## 🚀 Quick Start
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from doFolder import File, Directory, ItemType
|
|
57
|
+
|
|
58
|
+
# Create directory and file objects
|
|
59
|
+
project_dir = Directory("./my_project")
|
|
60
|
+
config_file = project_dir["config.json"]
|
|
61
|
+
|
|
62
|
+
# Create a new file in the directory
|
|
63
|
+
readme = project_dir.create("README.md", ItemType.FILE)
|
|
64
|
+
readme_zh = project_dir.createFile("README.zh-cn.md")
|
|
65
|
+
|
|
66
|
+
# Write content to the file
|
|
67
|
+
readme.content = "# My Project\n\nWelcome to my project!".encode("utf-8")
|
|
68
|
+
|
|
69
|
+
# Create a subdirectory
|
|
70
|
+
src_dir = project_dir.create("src", ItemType.DIR)
|
|
71
|
+
|
|
72
|
+
# Copy and move files
|
|
73
|
+
backup_config = config_file.copy("./backup/")
|
|
74
|
+
config_file.move("./settings/")
|
|
75
|
+
|
|
76
|
+
# List directory contents
|
|
77
|
+
for item in project_dir:
|
|
78
|
+
print(f"{item.name} ({'Directory' if item.isDir else 'File'})")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 📖 Usage Examples
|
|
82
|
+
|
|
83
|
+
### Working with Files
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from doFolder import File
|
|
87
|
+
|
|
88
|
+
# Create a file object
|
|
89
|
+
file = File("data.txt")
|
|
90
|
+
|
|
91
|
+
# Work with binary content
|
|
92
|
+
print(file.content) # Reads content as bytes
|
|
93
|
+
file.content = "Binary data here".encode("utf-8") # Writes content as bytes
|
|
94
|
+
|
|
95
|
+
# JSON operations
|
|
96
|
+
file.saveAsJson({"name": "John", "age": 30})
|
|
97
|
+
data = file.loadAsJson()
|
|
98
|
+
|
|
99
|
+
# Quickly open file
|
|
100
|
+
with file.open("w", encoding="utf-8") as f:
|
|
101
|
+
f.write("Hello, World!")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# File information
|
|
105
|
+
print(f"Size: {file.state.st_size} bytes")
|
|
106
|
+
print(f"Modified: {file.state.st_mtime}")
|
|
107
|
+
|
|
108
|
+
# File hashing
|
|
109
|
+
print(f"Hash: {file.hash()}")
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Working with Directories
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from doFolder import Directory, ItemType
|
|
116
|
+
|
|
117
|
+
# Create a directory object
|
|
118
|
+
d = Directory("./workspace")
|
|
119
|
+
|
|
120
|
+
# Create nested directory structure
|
|
121
|
+
d.create("src/utils", ItemType.DIR)
|
|
122
|
+
d.create("tests", ItemType.DIR)
|
|
123
|
+
d.createDir("docs")
|
|
124
|
+
d.createFile("README.md")
|
|
125
|
+
|
|
126
|
+
# Create files
|
|
127
|
+
main_file = d.create("src/main.py", ItemType.FILE)
|
|
128
|
+
test_file = d.create("tests/test_main.py", ItemType.FILE)
|
|
129
|
+
|
|
130
|
+
# List all items (non-recursive)
|
|
131
|
+
for item in d:
|
|
132
|
+
print(item.path)
|
|
133
|
+
|
|
134
|
+
# List all items recursively
|
|
135
|
+
for item in d.recursiveTraversal(hideDirectory=False):
|
|
136
|
+
print(f"{'📁' if item.isDir else '📄'} {item.path}")
|
|
137
|
+
|
|
138
|
+
# Find specific sub items
|
|
139
|
+
py_files = ['__init__.py']
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Advanced Operations
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from doFolder import File, Directory, compare
|
|
146
|
+
|
|
147
|
+
# File comparison
|
|
148
|
+
file1 = File("version1.txt")
|
|
149
|
+
file2 = File("version2.txt")
|
|
150
|
+
|
|
151
|
+
if compare.compare(file1, file2):
|
|
152
|
+
print("Files are identical")
|
|
153
|
+
else:
|
|
154
|
+
print("Files differ")
|
|
155
|
+
|
|
156
|
+
# Directory comparison
|
|
157
|
+
dir1 = Directory("./project_v1")
|
|
158
|
+
dir2 = Directory("./project_v2")
|
|
159
|
+
|
|
160
|
+
diff=getDifference(dir1, dir2)
|
|
161
|
+
|
|
162
|
+
# Hash verification
|
|
163
|
+
file = File("important_data.txt")
|
|
164
|
+
original_hash = file.hash()
|
|
165
|
+
# ... file operations ...
|
|
166
|
+
if file.hash() == original_hash:
|
|
167
|
+
print("File integrity verified")
|
|
168
|
+
|
|
169
|
+
# Safe operations with error handling
|
|
170
|
+
from doFolder import UnExistsMode
|
|
171
|
+
|
|
172
|
+
safe_file = File("might_not_exist.txt", unExists=UnExistsMode.CREATE)
|
|
173
|
+
# File will be created if it doesn't exist
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Path Utilities
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from doFolder import Path
|
|
180
|
+
|
|
181
|
+
# Enhanced path operations
|
|
182
|
+
path = Path("./documents/projects/my_app/src/main.py")
|
|
183
|
+
|
|
184
|
+
print(f"Project root: {path.parents[3]}") # ./documents/projects/my_app
|
|
185
|
+
print(f"Relative to project: {path.relative_to_parent(3)}") # src/main.py
|
|
186
|
+
print(f"Extension: {path.suffix}") # .py
|
|
187
|
+
print(f"Filename: {path.stem}") # main
|
|
188
|
+
|
|
189
|
+
# Path manipulation
|
|
190
|
+
config_path = path.sibling("config.json") # Same directory, different file
|
|
191
|
+
backup_path = path.with_name(f"{path.stem}_backup{path.suffix}")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## 🔧 Advanced Features
|
|
195
|
+
|
|
196
|
+
### Error Handling Modes
|
|
197
|
+
|
|
198
|
+
doFolder provides flexible error handling through `UnExistsMode`:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
from doFolder import File, UnExistsMode
|
|
202
|
+
|
|
203
|
+
# Different modes for handling non-existent files
|
|
204
|
+
file1 = File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exception
|
|
205
|
+
file2 = File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warning
|
|
206
|
+
file3 = File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handling
|
|
207
|
+
file4 = File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### File System Item Types
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from doFolder import ItemType, createItem
|
|
214
|
+
|
|
215
|
+
# Factory function to create appropriate objects
|
|
216
|
+
item1 = createItem("./some_path", ItemType.FILE) # Creates File object
|
|
217
|
+
item2 = createItem("./some_path", ItemType.DIR) # Creates Directory object
|
|
218
|
+
item3 = createItem("./some_path") # Auto-detects type
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## 🔄 Migration from v1.x.x
|
|
222
|
+
|
|
223
|
+
doFolder v2.x.x introduces several improvements while maintaining backward compatibility:
|
|
224
|
+
|
|
225
|
+
- **Enhanced Path Management**: Now uses Python's built-in `pathlib`
|
|
226
|
+
- **Renamed Classes**: `Folder` → `Directory` (backward compatibility maintained)
|
|
227
|
+
- **Flexible File Creation**: `File` class can handle directory paths with redirection
|
|
228
|
+
- **Improved Type Safety**: Full type hints throughout the codebase
|
|
229
|
+
|
|
230
|
+
### Migration Example
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
# v1.x.x style (still works)
|
|
234
|
+
from doFolder import Folder
|
|
235
|
+
folder = Folder("./my_directory")
|
|
236
|
+
|
|
237
|
+
# v2.x.x recommended style
|
|
238
|
+
from doFolder import Directory
|
|
239
|
+
directory = Directory("./my_directory")
|
|
240
|
+
|
|
241
|
+
# Both work identically!
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## 📚 Documentation
|
|
245
|
+
|
|
246
|
+
- **Full API Documentation**: [https://do-folder.doc.kuankuan.site](https://do-folder.doc.kuankuan.site)
|
|
247
|
+
- **GitHub Repository**: [https://github.com/kuankuan2007/do-folder](https://github.com/kuankuan2007/do-folder)
|
|
248
|
+
- **Issue Tracker**: [https://github.com/kuankuan2007/do-folder/issues](https://github.com/kuankuan2007/do-folder/issues)
|
|
249
|
+
|
|
250
|
+
## 🤝 Contributing
|
|
251
|
+
|
|
252
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
253
|
+
|
|
254
|
+
## 📄 License
|
|
255
|
+
|
|
256
|
+
This project is licensed under the [MulanPSL-2.0 License](./LICENSE) - see the LICENSE file for details.
|
dofolder-2.2.4/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# doFolder
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/doFolder) [](https://github.com/kuankuan2007/do-folder)  [](./LICENSE) [](https://do-folder.doc.kuankuan.site)
|
|
4
|
+
|
|
5
|
+
**doFolder** is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.
|
|
6
|
+
|
|
7
|
+
## ✨ Key Features
|
|
8
|
+
|
|
9
|
+
- **🎯 Object-oriented Design**: Work with files and directories as Python objects
|
|
10
|
+
- **🌐 Cross-platform Compatibility**: Seamlessly works on Windows, macOS, and Linux
|
|
11
|
+
- **🛤️ Advanced Path Handling**: Built on Python's pathlib for robust path management
|
|
12
|
+
- **📁 Complete File Operations**: Create, move, copy, delete, and modify files and directories
|
|
13
|
+
- **📝 Content Management**: Read and write file content with encoding support
|
|
14
|
+
- **🌳 Directory Tree Operations**: Navigate and manipulate directory structures
|
|
15
|
+
- **🔍 File Comparison**: Compare files and directories with various comparison modes
|
|
16
|
+
- **🔒 Hash Support**: Generate and verify file hashes for integrity checking
|
|
17
|
+
- **⚠️ Flexible Error Handling**: Comprehensive error modes for different use cases
|
|
18
|
+
- **🏷️ Type Safety**: Full type hints for better IDE support and code reliability
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install doFolder
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Requirements:** Python 3.8+
|
|
27
|
+
|
|
28
|
+
## 🚀 Quick Start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from doFolder import File, Directory, ItemType
|
|
32
|
+
|
|
33
|
+
# Create directory and file objects
|
|
34
|
+
project_dir = Directory("./my_project")
|
|
35
|
+
config_file = project_dir["config.json"]
|
|
36
|
+
|
|
37
|
+
# Create a new file in the directory
|
|
38
|
+
readme = project_dir.create("README.md", ItemType.FILE)
|
|
39
|
+
readme_zh = project_dir.createFile("README.zh-cn.md")
|
|
40
|
+
|
|
41
|
+
# Write content to the file
|
|
42
|
+
readme.content = "# My Project\n\nWelcome to my project!".encode("utf-8")
|
|
43
|
+
|
|
44
|
+
# Create a subdirectory
|
|
45
|
+
src_dir = project_dir.create("src", ItemType.DIR)
|
|
46
|
+
|
|
47
|
+
# Copy and move files
|
|
48
|
+
backup_config = config_file.copy("./backup/")
|
|
49
|
+
config_file.move("./settings/")
|
|
50
|
+
|
|
51
|
+
# List directory contents
|
|
52
|
+
for item in project_dir:
|
|
53
|
+
print(f"{item.name} ({'Directory' if item.isDir else 'File'})")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 📖 Usage Examples
|
|
57
|
+
|
|
58
|
+
### Working with Files
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from doFolder import File
|
|
62
|
+
|
|
63
|
+
# Create a file object
|
|
64
|
+
file = File("data.txt")
|
|
65
|
+
|
|
66
|
+
# Work with binary content
|
|
67
|
+
print(file.content) # Reads content as bytes
|
|
68
|
+
file.content = "Binary data here".encode("utf-8") # Writes content as bytes
|
|
69
|
+
|
|
70
|
+
# JSON operations
|
|
71
|
+
file.saveAsJson({"name": "John", "age": 30})
|
|
72
|
+
data = file.loadAsJson()
|
|
73
|
+
|
|
74
|
+
# Quickly open file
|
|
75
|
+
with file.open("w", encoding="utf-8") as f:
|
|
76
|
+
f.write("Hello, World!")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# File information
|
|
80
|
+
print(f"Size: {file.state.st_size} bytes")
|
|
81
|
+
print(f"Modified: {file.state.st_mtime}")
|
|
82
|
+
|
|
83
|
+
# File hashing
|
|
84
|
+
print(f"Hash: {file.hash()}")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Working with Directories
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from doFolder import Directory, ItemType
|
|
91
|
+
|
|
92
|
+
# Create a directory object
|
|
93
|
+
d = Directory("./workspace")
|
|
94
|
+
|
|
95
|
+
# Create nested directory structure
|
|
96
|
+
d.create("src/utils", ItemType.DIR)
|
|
97
|
+
d.create("tests", ItemType.DIR)
|
|
98
|
+
d.createDir("docs")
|
|
99
|
+
d.createFile("README.md")
|
|
100
|
+
|
|
101
|
+
# Create files
|
|
102
|
+
main_file = d.create("src/main.py", ItemType.FILE)
|
|
103
|
+
test_file = d.create("tests/test_main.py", ItemType.FILE)
|
|
104
|
+
|
|
105
|
+
# List all items (non-recursive)
|
|
106
|
+
for item in d:
|
|
107
|
+
print(item.path)
|
|
108
|
+
|
|
109
|
+
# List all items recursively
|
|
110
|
+
for item in d.recursiveTraversal(hideDirectory=False):
|
|
111
|
+
print(f"{'📁' if item.isDir else '📄'} {item.path}")
|
|
112
|
+
|
|
113
|
+
# Find specific sub items
|
|
114
|
+
py_files = ['__init__.py']
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Advanced Operations
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from doFolder import File, Directory, compare
|
|
121
|
+
|
|
122
|
+
# File comparison
|
|
123
|
+
file1 = File("version1.txt")
|
|
124
|
+
file2 = File("version2.txt")
|
|
125
|
+
|
|
126
|
+
if compare.compare(file1, file2):
|
|
127
|
+
print("Files are identical")
|
|
128
|
+
else:
|
|
129
|
+
print("Files differ")
|
|
130
|
+
|
|
131
|
+
# Directory comparison
|
|
132
|
+
dir1 = Directory("./project_v1")
|
|
133
|
+
dir2 = Directory("./project_v2")
|
|
134
|
+
|
|
135
|
+
diff=getDifference(dir1, dir2)
|
|
136
|
+
|
|
137
|
+
# Hash verification
|
|
138
|
+
file = File("important_data.txt")
|
|
139
|
+
original_hash = file.hash()
|
|
140
|
+
# ... file operations ...
|
|
141
|
+
if file.hash() == original_hash:
|
|
142
|
+
print("File integrity verified")
|
|
143
|
+
|
|
144
|
+
# Safe operations with error handling
|
|
145
|
+
from doFolder import UnExistsMode
|
|
146
|
+
|
|
147
|
+
safe_file = File("might_not_exist.txt", unExists=UnExistsMode.CREATE)
|
|
148
|
+
# File will be created if it doesn't exist
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Path Utilities
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from doFolder import Path
|
|
155
|
+
|
|
156
|
+
# Enhanced path operations
|
|
157
|
+
path = Path("./documents/projects/my_app/src/main.py")
|
|
158
|
+
|
|
159
|
+
print(f"Project root: {path.parents[3]}") # ./documents/projects/my_app
|
|
160
|
+
print(f"Relative to project: {path.relative_to_parent(3)}") # src/main.py
|
|
161
|
+
print(f"Extension: {path.suffix}") # .py
|
|
162
|
+
print(f"Filename: {path.stem}") # main
|
|
163
|
+
|
|
164
|
+
# Path manipulation
|
|
165
|
+
config_path = path.sibling("config.json") # Same directory, different file
|
|
166
|
+
backup_path = path.with_name(f"{path.stem}_backup{path.suffix}")
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 🔧 Advanced Features
|
|
170
|
+
|
|
171
|
+
### Error Handling Modes
|
|
172
|
+
|
|
173
|
+
doFolder provides flexible error handling through `UnExistsMode`:
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from doFolder import File, UnExistsMode
|
|
177
|
+
|
|
178
|
+
# Different modes for handling non-existent files
|
|
179
|
+
file1 = File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exception
|
|
180
|
+
file2 = File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warning
|
|
181
|
+
file3 = File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handling
|
|
182
|
+
file4 = File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### File System Item Types
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
from doFolder import ItemType, createItem
|
|
189
|
+
|
|
190
|
+
# Factory function to create appropriate objects
|
|
191
|
+
item1 = createItem("./some_path", ItemType.FILE) # Creates File object
|
|
192
|
+
item2 = createItem("./some_path", ItemType.DIR) # Creates Directory object
|
|
193
|
+
item3 = createItem("./some_path") # Auto-detects type
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## 🔄 Migration from v1.x.x
|
|
197
|
+
|
|
198
|
+
doFolder v2.x.x introduces several improvements while maintaining backward compatibility:
|
|
199
|
+
|
|
200
|
+
- **Enhanced Path Management**: Now uses Python's built-in `pathlib`
|
|
201
|
+
- **Renamed Classes**: `Folder` → `Directory` (backward compatibility maintained)
|
|
202
|
+
- **Flexible File Creation**: `File` class can handle directory paths with redirection
|
|
203
|
+
- **Improved Type Safety**: Full type hints throughout the codebase
|
|
204
|
+
|
|
205
|
+
### Migration Example
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
# v1.x.x style (still works)
|
|
209
|
+
from doFolder import Folder
|
|
210
|
+
folder = Folder("./my_directory")
|
|
211
|
+
|
|
212
|
+
# v2.x.x recommended style
|
|
213
|
+
from doFolder import Directory
|
|
214
|
+
directory = Directory("./my_directory")
|
|
215
|
+
|
|
216
|
+
# Both work identically!
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## 📚 Documentation
|
|
220
|
+
|
|
221
|
+
- **Full API Documentation**: [https://do-folder.doc.kuankuan.site](https://do-folder.doc.kuankuan.site)
|
|
222
|
+
- **GitHub Repository**: [https://github.com/kuankuan2007/do-folder](https://github.com/kuankuan2007/do-folder)
|
|
223
|
+
- **Issue Tracker**: [https://github.com/kuankuan2007/do-folder/issues](https://github.com/kuankuan2007/do-folder/issues)
|
|
224
|
+
|
|
225
|
+
## 🤝 Contributing
|
|
226
|
+
|
|
227
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
228
|
+
|
|
229
|
+
## 📄 License
|
|
230
|
+
|
|
231
|
+
This project is licensed under the [MulanPSL-2.0 License](./LICENSE) - see the LICENSE file for details.
|
|
@@ -4,7 +4,6 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "doFolder"
|
|
7
|
-
version = "2.2.2"
|
|
8
7
|
description = "Manage files more easily"
|
|
9
8
|
authors = [
|
|
10
9
|
{ name = "kuankuan", email = "2163826131@qq.com" },
|
|
@@ -12,10 +11,11 @@ authors = [
|
|
|
12
11
|
readme = "README.md"
|
|
13
12
|
license = "MulanPSL-2.0"
|
|
14
13
|
requires-python = ">=3.8"
|
|
14
|
+
dynamic = ["version"]
|
|
15
15
|
|
|
16
16
|
classifiers = [
|
|
17
17
|
"Natural Language :: English",
|
|
18
|
-
"Development Status ::
|
|
18
|
+
"Development Status :: 5 - Production/Stable",
|
|
19
19
|
"Intended Audience :: Developers",
|
|
20
20
|
"Programming Language :: Python :: 3",
|
|
21
21
|
"Operating System :: MacOS",
|
|
@@ -38,3 +38,6 @@ python_version = "3.12"
|
|
|
38
38
|
exclude = [
|
|
39
39
|
'^testcases\.py$',
|
|
40
40
|
]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.dynamic]
|
|
43
|
+
version = { attr = "doFolder.__pkginfo__.__version__" }
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""
|
|
2
|
+
doFolder - A One Stop File System Management Library
|
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
4
|
+
|
|
5
|
+
doFolder is a powerful, intuitive, and cross-platform file system management library
|
|
6
|
+
that provides a high-level, object-oriented interface for working with files and
|
|
7
|
+
directories. It simplifies common file operations such as creating, moving, copying,
|
|
8
|
+
deleting, and comparing files and directories while offering advanced features like
|
|
9
|
+
hashing, content manipulation, and directory tree operations.
|
|
10
|
+
|
|
11
|
+
Key Features:
|
|
12
|
+
* **Object-oriented Design**: Work with files and directories as Python objects
|
|
13
|
+
* **Cross-platform Compatibility**: Seamlessly works on Windows, macOS, and Linux
|
|
14
|
+
* **Advanced Path Handling**: Built on Python's pathlib for robust path management
|
|
15
|
+
* **File Operations**: Create, move, copy, delete, and modify files and directories
|
|
16
|
+
* **Content Management**: Read and write file content with encoding support
|
|
17
|
+
* **Directory Tree Operations**: Navigate and manipulate directory structures
|
|
18
|
+
* **File Comparison**: Compare files and directories with various comparison modes
|
|
19
|
+
* **Hash Support**: Generate and verify file hashes for integrity checking
|
|
20
|
+
* **Error Handling**: Comprehensive error modes for different use cases
|
|
21
|
+
* **Type Safety**: Full type hints for better IDE support and code reliability
|
|
22
|
+
|
|
23
|
+
Quick Start:
|
|
24
|
+
>>> import doFolder
|
|
25
|
+
>>>
|
|
26
|
+
>>> # Create directory and file objects
|
|
27
|
+
>>> project_dir = doFolder.Directory("./my_project")
|
|
28
|
+
>>> config_file = doFolder.File("./my_project/config.json")
|
|
29
|
+
>>>
|
|
30
|
+
>>> # Create a new file in the directory
|
|
31
|
+
>>> new_file = project_dir.create("readme.txt", doFolder.ItemType.FILE)
|
|
32
|
+
>>>
|
|
33
|
+
>>> # Write content to the file
|
|
34
|
+
>>> new_file.content = "Hello, World!".encode("utf-8")
|
|
35
|
+
>>>
|
|
36
|
+
>>> # Create a subdirectory
|
|
37
|
+
>>> sub_dir = project_dir.create("data", doFolder.ItemType.DIR)
|
|
38
|
+
>>>
|
|
39
|
+
>>> # Copy and move files
|
|
40
|
+
>>> backup_file = new_file.copy("./backup/")
|
|
41
|
+
>>> new_file.move("./archive/")
|
|
42
|
+
|
|
43
|
+
Main Classes:
|
|
44
|
+
* **File**: Represents a file in the file system with methods for content
|
|
45
|
+
manipulation, copying, moving, and deletion.
|
|
46
|
+
* **Directory**: Represents a directory with methods for creating, listing,
|
|
47
|
+
and managing contained files and subdirectories.
|
|
48
|
+
* **Path**: Enhanced path handling with additional utility methods.
|
|
49
|
+
|
|
50
|
+
Enums and Types:
|
|
51
|
+
* **ItemType**: Enumeration for file system item types (FILE, DIR).
|
|
52
|
+
* **UnExistsMode**: Defines behavior when a path doesn't exist (WARN, ERROR,
|
|
53
|
+
IGNORE, CREATE).
|
|
54
|
+
|
|
55
|
+
Utility Functions:
|
|
56
|
+
* **createItem()**: Factory function to create File or Directory objects
|
|
57
|
+
based on path type.
|
|
58
|
+
* **isDir()**: Type guard to check if an item is a directory.
|
|
59
|
+
|
|
60
|
+
Advanced Features:
|
|
61
|
+
* **File Comparison**: The `compare` module provides comprehensive comparison
|
|
62
|
+
capabilities for files and directories.
|
|
63
|
+
* **Hash Operations**: Built-in support for file hashing and verification.
|
|
64
|
+
* **Flexible Error Handling**: Configurable error modes for different
|
|
65
|
+
scenarios.
|
|
66
|
+
* **Path Utilities**: Advanced path manipulation and formatting functions.
|
|
67
|
+
|
|
68
|
+
:copyright: (c) 2023-2025 by kuankuan2007.
|
|
69
|
+
:license: MulanPSL-2.0, see LICENSE for more details.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
# Core file system classes and utilities
|
|
73
|
+
from .fileSystem import (
|
|
74
|
+
File, # Class for file operations and management
|
|
75
|
+
Directory, # Class for directory operations and management
|
|
76
|
+
ItemType, # Enum defining file system item types (FILE, DIR)
|
|
77
|
+
UnExistsMode, # Enum defining behavior when paths don't exist
|
|
78
|
+
Folder, # Backward-compatible alias for Directory
|
|
79
|
+
createItem, # Factory function to create File or Directory objects
|
|
80
|
+
isDir, # Type guard to check if an object is a Directory
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Enhanced path handling
|
|
84
|
+
from .path import Path # Extended Path class with additional utilities
|
|
85
|
+
|
|
86
|
+
# File and directory comparison module
|
|
87
|
+
from . import compare # Comprehensive comparison utilities
|
|
88
|
+
|
|
89
|
+
# Package metadata
|
|
90
|
+
from .__pkginfo__ import __version__ # Package version information
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
__all__ = [
|
|
94
|
+
"File",
|
|
95
|
+
"Directory",
|
|
96
|
+
"Folder",
|
|
97
|
+
"ItemType",
|
|
98
|
+
"UnExistsMode",
|
|
99
|
+
"Path",
|
|
100
|
+
"createItem",
|
|
101
|
+
"isDir",
|
|
102
|
+
"compare",
|
|
103
|
+
"__version__",
|
|
104
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Package metadata and version information for doFolder.
|
|
3
|
+
|
|
4
|
+
This module defines the core package metadata including version numbers,
|
|
5
|
+
package name, and other essential identifiers for the doFolder library.
|
|
6
|
+
doFolder is a comprehensive file and directory management toolkit that
|
|
7
|
+
provides object-oriented interfaces for cross-platform file operations.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__version__ = "2.2.4"
|
|
11
|
+
__pkgname__ = 'doFolder'
|