sortnest 0.1.0__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.
- sortnest-0.1.0/LICENSE +24 -0
- sortnest-0.1.0/PKG-INFO +62 -0
- sortnest-0.1.0/README.md +46 -0
- sortnest-0.1.0/pyproject.toml +26 -0
- sortnest-0.1.0/setup.cfg +4 -0
- sortnest-0.1.0/src/sortnest/__init__.py +3 -0
- sortnest-0.1.0/src/sortnest/__main__.py +5 -0
- sortnest-0.1.0/src/sortnest/organizer.py +146 -0
- sortnest-0.1.0/src/sortnest.egg-info/PKG-INFO +62 -0
- sortnest-0.1.0/src/sortnest.egg-info/SOURCES.txt +11 -0
- sortnest-0.1.0/src/sortnest.egg-info/dependency_links.txt +1 -0
- sortnest-0.1.0/src/sortnest.egg-info/entry_points.txt +2 -0
- sortnest-0.1.0/src/sortnest.egg-info/top_level.txt +1 -0
sortnest-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sortnest authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
|
6
|
+
obtaining a copy of this software and associated documentation
|
|
7
|
+
files (the "Software"), to deal in the Software without
|
|
8
|
+
restriction, including without limitation the rights to use,
|
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or
|
|
10
|
+
sell copies of the Software, and to permit persons to whom the
|
|
11
|
+
Software is furnished to do so, subject to the following
|
|
12
|
+
conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
sortnest-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sortnest
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tidy a folder by file type, with preview and undo.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Keywords: organizer,files,cleanup,downloads,cli
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Environment :: Console
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Topic :: System :: Filesystems
|
|
11
|
+
Classifier: Topic :: Utilities
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# sortnest
|
|
18
|
+
|
|
19
|
+
Tidy any folder by file type. It shows a preview first,
|
|
20
|
+
and you can undo the last run at any time.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- Sorts files into folders: Images, Videos, Music, Documents,
|
|
25
|
+
Archives, Programs, Code and Others
|
|
26
|
+
- Preview before anything is moved
|
|
27
|
+
- One-step undo
|
|
28
|
+
- Never overwrites: name clashes become `file (1).ext`
|
|
29
|
+
- No dependencies, pure Python
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
pip install sortnest
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
sortnest
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or, without installing the command:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
python -m sortnest
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then enter a folder path (press Enter for your Downloads
|
|
50
|
+
folder) and choose:
|
|
51
|
+
|
|
52
|
+
1. Organize files
|
|
53
|
+
2. Undo last organize
|
|
54
|
+
|
|
55
|
+
## Customize
|
|
56
|
+
|
|
57
|
+
Open `src/sortnest/organizer.py` and edit the `CATEGORIES`
|
|
58
|
+
dictionary to add your own file types.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
sortnest-0.1.0/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# sortnest
|
|
2
|
+
|
|
3
|
+
Tidy any folder by file type. It shows a preview first,
|
|
4
|
+
and you can undo the last run at any time.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- Sorts files into folders: Images, Videos, Music, Documents,
|
|
9
|
+
Archives, Programs, Code and Others
|
|
10
|
+
- Preview before anything is moved
|
|
11
|
+
- One-step undo
|
|
12
|
+
- Never overwrites: name clashes become `file (1).ext`
|
|
13
|
+
- No dependencies, pure Python
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
pip install sortnest
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
sortnest
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or, without installing the command:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
python -m sortnest
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then enter a folder path (press Enter for your Downloads
|
|
34
|
+
folder) and choose:
|
|
35
|
+
|
|
36
|
+
1. Organize files
|
|
37
|
+
2. Undo last organize
|
|
38
|
+
|
|
39
|
+
## Customize
|
|
40
|
+
|
|
41
|
+
Open `src/sortnest/organizer.py` and edit the `CATEGORIES`
|
|
42
|
+
dictionary to add your own file types.
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sortnest"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Tidy a folder by file type, with preview and undo."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
keywords = ["organizer", "files", "cleanup", "downloads", "cli"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: System :: Filesystems",
|
|
19
|
+
"Topic :: Utilities",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
sortnest = "sortnest.organizer:main"
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
sortnest-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""
|
|
2
|
+
File Organizer
|
|
3
|
+
|
|
4
|
+
Sorts the files in a folder into sub-folders by type.
|
|
5
|
+
Shows a preview first, and can undo the last run.
|
|
6
|
+
|
|
7
|
+
Usage: python organizer.py
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import shutil
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
# Folder name -> file extensions that belong in it.
|
|
15
|
+
CATEGORIES = {
|
|
16
|
+
"Images": {".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp"},
|
|
17
|
+
"Videos": {".mp4", ".mkv", ".avi", ".mov", ".wmv"},
|
|
18
|
+
"Music": {".mp3", ".wav", ".flac", ".m4a"},
|
|
19
|
+
"Documents": {
|
|
20
|
+
".pdf", ".doc", ".docx", ".txt",
|
|
21
|
+
".xls", ".xlsx", ".ppt", ".pptx", ".csv",
|
|
22
|
+
},
|
|
23
|
+
"Archives": {".zip", ".rar", ".7z", ".tar", ".gz"},
|
|
24
|
+
"Programs": {".exe", ".msi"},
|
|
25
|
+
"Code": {".py", ".js", ".html", ".css", ".json"},
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Unfinished downloads are left alone.
|
|
29
|
+
SKIP_EXTENSIONS = {".crdownload", ".part", ".tmp"}
|
|
30
|
+
|
|
31
|
+
# History file used by Undo.
|
|
32
|
+
LOG_NAME = ".organizer_log.json"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_category(file):
|
|
36
|
+
"""Return the category name for a file."""
|
|
37
|
+
ext = file.suffix.lower()
|
|
38
|
+
for category, extensions in CATEGORIES.items():
|
|
39
|
+
if ext in extensions:
|
|
40
|
+
return category
|
|
41
|
+
return "Others"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def unique_path(path):
|
|
45
|
+
"""Add (1), (2), ... if the file name is already taken."""
|
|
46
|
+
if not path.exists():
|
|
47
|
+
return path
|
|
48
|
+
counter = 1
|
|
49
|
+
while True:
|
|
50
|
+
name = f"{path.stem} ({counter}){path.suffix}"
|
|
51
|
+
new_path = path.with_name(name)
|
|
52
|
+
if not new_path.exists():
|
|
53
|
+
return new_path
|
|
54
|
+
counter += 1
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def plan_moves(folder):
|
|
58
|
+
"""List (source, destination) pairs. Moves nothing."""
|
|
59
|
+
moves = []
|
|
60
|
+
for item in folder.iterdir():
|
|
61
|
+
if not item.is_file():
|
|
62
|
+
continue
|
|
63
|
+
if item.name == LOG_NAME:
|
|
64
|
+
continue
|
|
65
|
+
if item.suffix.lower() in SKIP_EXTENSIONS:
|
|
66
|
+
continue
|
|
67
|
+
target = folder / get_category(item) / item.name
|
|
68
|
+
moves.append((item, unique_path(target)))
|
|
69
|
+
return moves
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def organize(folder):
|
|
73
|
+
"""Preview, ask for confirmation, then move the files."""
|
|
74
|
+
moves = plan_moves(folder)
|
|
75
|
+
if not moves:
|
|
76
|
+
print("Nothing to organize here.")
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
print(f"\nPreview ({len(moves)} files):")
|
|
80
|
+
for src, dst in moves:
|
|
81
|
+
print(f" {src.name} -> {dst.parent.name}/")
|
|
82
|
+
|
|
83
|
+
answer = input("\nProceed? (y/n): ").strip().lower()
|
|
84
|
+
if answer != "y":
|
|
85
|
+
print("Cancelled. Nothing was changed.")
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
log = []
|
|
89
|
+
for src, dst in moves:
|
|
90
|
+
dst.parent.mkdir(exist_ok=True)
|
|
91
|
+
shutil.move(str(src), str(dst))
|
|
92
|
+
log.append({"from": str(src), "to": str(dst)})
|
|
93
|
+
|
|
94
|
+
log_file = folder / LOG_NAME
|
|
95
|
+
log_file.write_text(json.dumps(log, indent=2), encoding="utf-8")
|
|
96
|
+
print(f"\nDone! Moved {len(log)} files.")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def undo(folder):
|
|
100
|
+
"""Move files back and remove empty category folders."""
|
|
101
|
+
log_file = folder / LOG_NAME
|
|
102
|
+
if not log_file.exists():
|
|
103
|
+
print("No previous run found to undo.")
|
|
104
|
+
return
|
|
105
|
+
|
|
106
|
+
log = json.loads(log_file.read_text(encoding="utf-8"))
|
|
107
|
+
restored = 0
|
|
108
|
+
for entry in reversed(log):
|
|
109
|
+
src = Path(entry["from"])
|
|
110
|
+
dst = Path(entry["to"])
|
|
111
|
+
if not dst.exists():
|
|
112
|
+
continue
|
|
113
|
+
shutil.move(str(dst), str(unique_path(src)))
|
|
114
|
+
restored += 1
|
|
115
|
+
if not any(dst.parent.iterdir()):
|
|
116
|
+
dst.parent.rmdir()
|
|
117
|
+
|
|
118
|
+
log_file.unlink()
|
|
119
|
+
print(f"Undo complete. Restored {restored} files.")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def main():
|
|
123
|
+
"""Ask for a folder, then organize it or undo the last run."""
|
|
124
|
+
default = Path.home() / "Downloads"
|
|
125
|
+
text = input(f"Folder path (Enter = {default}): ")
|
|
126
|
+
text = text.strip().strip('"')
|
|
127
|
+
folder = Path(text) if text else default
|
|
128
|
+
|
|
129
|
+
if not folder.is_dir():
|
|
130
|
+
print("That folder does not exist.")
|
|
131
|
+
return
|
|
132
|
+
|
|
133
|
+
print("\n1) Organize files")
|
|
134
|
+
print("2) Undo last organize")
|
|
135
|
+
choice = input("Choose 1 or 2: ").strip()
|
|
136
|
+
|
|
137
|
+
if choice == "1":
|
|
138
|
+
organize(folder)
|
|
139
|
+
elif choice == "2":
|
|
140
|
+
undo(folder)
|
|
141
|
+
else:
|
|
142
|
+
print("Invalid choice.")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if __name__ == "__main__":
|
|
146
|
+
main()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sortnest
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tidy a folder by file type, with preview and undo.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Keywords: organizer,files,cleanup,downloads,cli
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Environment :: Console
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Topic :: System :: Filesystems
|
|
11
|
+
Classifier: Topic :: Utilities
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# sortnest
|
|
18
|
+
|
|
19
|
+
Tidy any folder by file type. It shows a preview first,
|
|
20
|
+
and you can undo the last run at any time.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- Sorts files into folders: Images, Videos, Music, Documents,
|
|
25
|
+
Archives, Programs, Code and Others
|
|
26
|
+
- Preview before anything is moved
|
|
27
|
+
- One-step undo
|
|
28
|
+
- Never overwrites: name clashes become `file (1).ext`
|
|
29
|
+
- No dependencies, pure Python
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
pip install sortnest
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
sortnest
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or, without installing the command:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
python -m sortnest
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then enter a folder path (press Enter for your Downloads
|
|
50
|
+
folder) and choose:
|
|
51
|
+
|
|
52
|
+
1. Organize files
|
|
53
|
+
2. Undo last organize
|
|
54
|
+
|
|
55
|
+
## Customize
|
|
56
|
+
|
|
57
|
+
Open `src/sortnest/organizer.py` and edit the `CATEGORIES`
|
|
58
|
+
dictionary to add your own file types.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/sortnest/__init__.py
|
|
5
|
+
src/sortnest/__main__.py
|
|
6
|
+
src/sortnest/organizer.py
|
|
7
|
+
src/sortnest.egg-info/PKG-INFO
|
|
8
|
+
src/sortnest.egg-info/SOURCES.txt
|
|
9
|
+
src/sortnest.egg-info/dependency_links.txt
|
|
10
|
+
src/sortnest.egg-info/entry_points.txt
|
|
11
|
+
src/sortnest.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sortnest
|