lightnamer 1.0.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Farhan Madni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.4
2
+ Name: lightnamer
3
+ Version: 1.0.0
4
+ Summary: LightNamer is a CLI tool for renaming 100s of files in seconds.
5
+ Author-email: Farhan Madni <madnifm347@outlook.com>
6
+ Project-URL: Homepage, https://github.com/MFM-347/LightNamer
7
+ Keywords: renamer,cli,auto,automation,automatic,python,opensource
8
+ Classifier: Programming Language :: Python
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Provides-Extra: dev
14
+ Requires-Dist: black; extra == "dev"
15
+ Requires-Dist: flake8; extra == "dev"
16
+ Requires-Dist: bumpver; extra == "dev"
17
+ Requires-Dist: isort; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+ # **LightNamer: CLI & Library for Auto Renaming** ๐Ÿš€
21
+
22
+ LightNamer is a **Python library and CLI tool** designed to **automate file renaming** in a given directory. It sequentially renames files using a specified **base name**, appending a numeric index while preserving the original file extension.
23
+
24
+ ## **๐Ÿ“Œ Features**
25
+
26
+ | Feature | Availability | Description |
27
+ | ------------------- | ------------ | ----------------------------------------------------------------------------- |
28
+ | **Batch Rename** | โœ” | Rename multiple files at once with a custom prefix. |
29
+ | **Sorting Options** | โœ” | Rename files in alphabetical, newest, or oldest order. |
30
+ | **Simulation Mode** | โœ” | Preview renaming changes without modifying files. No actual changes are made. |
31
+ | **Library Support** | โœ” | Use LightNamer as a module in your Python scripts for automation. |
32
+ | **Cross-Platform** | โœ” | Works seamlessly on Windows, macOS, and Linux. |
33
+
34
+ ## **๐Ÿ› ๏ธ Prerequisites**
35
+
36
+ - **Python 3.x** installed
37
+ - Basic knowledge of **command-line usage**
38
+
39
+ ### **๐Ÿ“ฆ Required Python Packages**
40
+
41
+ LightNamer requires the following package(s):
42
+
43
+ - `pyfiglet` (for CLI banner text)
44
+
45
+ To install dependencies, run:
46
+
47
+ ```sh
48
+ pip install -r requirements.txt # Use pip3 on macOS
49
+ ```
50
+
51
+ ## **โšก Installation**
52
+
53
+ ### **๐Ÿ”น Install via Pip**
54
+
55
+ To install LightNamer as a library:
56
+
57
+ ```sh
58
+ pip install lightnamer
59
+ ```
60
+
61
+ ### **๐Ÿ”น Install from Source**
62
+
63
+ To install and run the tool from the source code:
64
+
65
+ ```sh
66
+ git clone https://github.com/MFM-347/LightNamer.git
67
+ cd LightNamer
68
+ pip install .
69
+ ```
70
+
71
+ ## **๐Ÿ’ป CLI Usage**
72
+
73
+ ### **๐Ÿ“Œ Run the CLI**
74
+
75
+ ```sh
76
+ lightnamer <base_name> <directory> [-r <order>] [-s]
77
+ ```
78
+
79
+ ### **Example**
80
+
81
+ Rename files inside `C:\Users\YourName\Documents\Folder`, using "File" as the base name:
82
+
83
+ ```sh
84
+ lightnamer "File" C:\Users\YourName\Documents\Folder
85
+ ```
86
+
87
+ ### **๐Ÿ“‚ Given Directory (`C:\Docs`)**
88
+
89
+ ```
90
+ report.docx
91
+ notes.txt
92
+ summary.pdf
93
+ ```
94
+
95
+ ### **๐Ÿท๏ธ Renaming Command**
96
+
97
+ ```sh
98
+ lightnamer "Document" C:\Docs -r alphabet
99
+ ```
100
+
101
+ ### **๐Ÿ“ Output**
102
+
103
+ ```
104
+ Document-1.docx
105
+ Document-2.pdf
106
+ Document-3.txt
107
+ ```
108
+
109
+ ## **โš™๏ธ Command-Line Options**
110
+
111
+ | Option | Description |
112
+ | --------------------- | -------------------------------------------- |
113
+ | `<base_name>` | Prefix for renamed files. |
114
+ | `<directory>` | Path to folder containing the files. |
115
+ | `-r, --order <order>` | Sorting order before renaming: |
116
+ | | - `alphabet` โ†’ A-Z order |
117
+ | | - `new` โ†’ Newest to oldest |
118
+ | | - `old` โ†’ Oldest to newest (default) |
119
+ | `-s, --simulate` | Run a **simulation** without renaming files. |
120
+ | `--case-sensitive` | Sorts filenames in case-sensitive mode. |
121
+ | `--debug` | Enables debug logging. |
122
+
123
+ ## **๐Ÿ“ฆ Using LightNamer as a Library**
124
+
125
+ ### **๐Ÿ”น Installed Library Usage**
126
+
127
+ If you have installed LightNamer via `pip`, you can use it in your Python scripts as follows:
128
+
129
+ ```python
130
+ from lightnamer import renFn
131
+ from pathlib import Path
132
+
133
+ directory = Path("C:/Users/YourName/Documents/Folder")
134
+ renFn(base_name="Document", directory=directory, order="alphabet", simulate=False, case_sensitive=False)
135
+ ```
136
+
137
+ ### **๐Ÿ”น Source Code Usage**
138
+
139
+ If running directly from the cloned source repository:
140
+
141
+ ```python
142
+ from lightnamer import renFn
143
+ from pathlib import Path
144
+
145
+ directory = Path("C:/Users/YourName/Documents/Folder")
146
+ renFn(base_name="Document", directory=directory, order="alphabet", simulate=False, case_sensitive=False)
147
+ ```
148
+
149
+ ### **Sorting Files Only**
150
+
151
+ If you only need to **get sorted files** without renaming:
152
+
153
+ ```python
154
+ from lightnamer import sortFn
155
+ from pathlib import Path
156
+
157
+ directory = Path("/path/to/files")
158
+ sorted_files = sortFn(directory, order="new", case_sensitive=True)
159
+ print(sorted_files)
160
+ ```
161
+
162
+ ### **Handling Errors Gracefully**
163
+
164
+ You can wrap it in a try-except block:
165
+
166
+ ```python
167
+ try:
168
+ renFn("Example", Path("/home/user/files"), "old", False, False)
169
+ except Exception as e:
170
+ print(f"An error occurred: {e}")
171
+ ```
172
+
173
+ ## **๐Ÿงช Running Tests (For Source Code Only)**
174
+
175
+ Run all tests:
176
+
177
+ ```sh
178
+ python -m unittest discover tests
179
+ ```
180
+
181
+ ## Future Plans
182
+
183
+ - Add option to rename only specific file type.
184
+ - Add Graphic User Interface (GUI).
185
+
186
+ ## **๐Ÿค Contributing**
187
+
188
+ We welcome contributions! Please check the [CONTRIBUTING.md](https://github.com/MFM-347/LightNamer/blob/main/CONTRIBUTING.md) for guidelines.
189
+
190
+ ## **๐Ÿ‘จโ€๐Ÿ’ป Credits**
191
+
192
+ Created and maintained by [MFM-347](https://github.com/MFM-347).
193
+
194
+ ## **๐Ÿ“œ License**
195
+
196
+ This project is licensed under the **MIT License**.
197
+
198
+ [![License MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/MFM-347/LightNamer/LICENSE)
@@ -0,0 +1,179 @@
1
+ # **LightNamer: CLI & Library for Auto Renaming** ๐Ÿš€
2
+
3
+ LightNamer is a **Python library and CLI tool** designed to **automate file renaming** in a given directory. It sequentially renames files using a specified **base name**, appending a numeric index while preserving the original file extension.
4
+
5
+ ## **๐Ÿ“Œ Features**
6
+
7
+ | Feature | Availability | Description |
8
+ | ------------------- | ------------ | ----------------------------------------------------------------------------- |
9
+ | **Batch Rename** | โœ” | Rename multiple files at once with a custom prefix. |
10
+ | **Sorting Options** | โœ” | Rename files in alphabetical, newest, or oldest order. |
11
+ | **Simulation Mode** | โœ” | Preview renaming changes without modifying files. No actual changes are made. |
12
+ | **Library Support** | โœ” | Use LightNamer as a module in your Python scripts for automation. |
13
+ | **Cross-Platform** | โœ” | Works seamlessly on Windows, macOS, and Linux. |
14
+
15
+ ## **๐Ÿ› ๏ธ Prerequisites**
16
+
17
+ - **Python 3.x** installed
18
+ - Basic knowledge of **command-line usage**
19
+
20
+ ### **๐Ÿ“ฆ Required Python Packages**
21
+
22
+ LightNamer requires the following package(s):
23
+
24
+ - `pyfiglet` (for CLI banner text)
25
+
26
+ To install dependencies, run:
27
+
28
+ ```sh
29
+ pip install -r requirements.txt # Use pip3 on macOS
30
+ ```
31
+
32
+ ## **โšก Installation**
33
+
34
+ ### **๐Ÿ”น Install via Pip**
35
+
36
+ To install LightNamer as a library:
37
+
38
+ ```sh
39
+ pip install lightnamer
40
+ ```
41
+
42
+ ### **๐Ÿ”น Install from Source**
43
+
44
+ To install and run the tool from the source code:
45
+
46
+ ```sh
47
+ git clone https://github.com/MFM-347/LightNamer.git
48
+ cd LightNamer
49
+ pip install .
50
+ ```
51
+
52
+ ## **๐Ÿ’ป CLI Usage**
53
+
54
+ ### **๐Ÿ“Œ Run the CLI**
55
+
56
+ ```sh
57
+ lightnamer <base_name> <directory> [-r <order>] [-s]
58
+ ```
59
+
60
+ ### **Example**
61
+
62
+ Rename files inside `C:\Users\YourName\Documents\Folder`, using "File" as the base name:
63
+
64
+ ```sh
65
+ lightnamer "File" C:\Users\YourName\Documents\Folder
66
+ ```
67
+
68
+ ### **๐Ÿ“‚ Given Directory (`C:\Docs`)**
69
+
70
+ ```
71
+ report.docx
72
+ notes.txt
73
+ summary.pdf
74
+ ```
75
+
76
+ ### **๐Ÿท๏ธ Renaming Command**
77
+
78
+ ```sh
79
+ lightnamer "Document" C:\Docs -r alphabet
80
+ ```
81
+
82
+ ### **๐Ÿ“ Output**
83
+
84
+ ```
85
+ Document-1.docx
86
+ Document-2.pdf
87
+ Document-3.txt
88
+ ```
89
+
90
+ ## **โš™๏ธ Command-Line Options**
91
+
92
+ | Option | Description |
93
+ | --------------------- | -------------------------------------------- |
94
+ | `<base_name>` | Prefix for renamed files. |
95
+ | `<directory>` | Path to folder containing the files. |
96
+ | `-r, --order <order>` | Sorting order before renaming: |
97
+ | | - `alphabet` โ†’ A-Z order |
98
+ | | - `new` โ†’ Newest to oldest |
99
+ | | - `old` โ†’ Oldest to newest (default) |
100
+ | `-s, --simulate` | Run a **simulation** without renaming files. |
101
+ | `--case-sensitive` | Sorts filenames in case-sensitive mode. |
102
+ | `--debug` | Enables debug logging. |
103
+
104
+ ## **๐Ÿ“ฆ Using LightNamer as a Library**
105
+
106
+ ### **๐Ÿ”น Installed Library Usage**
107
+
108
+ If you have installed LightNamer via `pip`, you can use it in your Python scripts as follows:
109
+
110
+ ```python
111
+ from lightnamer import renFn
112
+ from pathlib import Path
113
+
114
+ directory = Path("C:/Users/YourName/Documents/Folder")
115
+ renFn(base_name="Document", directory=directory, order="alphabet", simulate=False, case_sensitive=False)
116
+ ```
117
+
118
+ ### **๐Ÿ”น Source Code Usage**
119
+
120
+ If running directly from the cloned source repository:
121
+
122
+ ```python
123
+ from lightnamer import renFn
124
+ from pathlib import Path
125
+
126
+ directory = Path("C:/Users/YourName/Documents/Folder")
127
+ renFn(base_name="Document", directory=directory, order="alphabet", simulate=False, case_sensitive=False)
128
+ ```
129
+
130
+ ### **Sorting Files Only**
131
+
132
+ If you only need to **get sorted files** without renaming:
133
+
134
+ ```python
135
+ from lightnamer import sortFn
136
+ from pathlib import Path
137
+
138
+ directory = Path("/path/to/files")
139
+ sorted_files = sortFn(directory, order="new", case_sensitive=True)
140
+ print(sorted_files)
141
+ ```
142
+
143
+ ### **Handling Errors Gracefully**
144
+
145
+ You can wrap it in a try-except block:
146
+
147
+ ```python
148
+ try:
149
+ renFn("Example", Path("/home/user/files"), "old", False, False)
150
+ except Exception as e:
151
+ print(f"An error occurred: {e}")
152
+ ```
153
+
154
+ ## **๐Ÿงช Running Tests (For Source Code Only)**
155
+
156
+ Run all tests:
157
+
158
+ ```sh
159
+ python -m unittest discover tests
160
+ ```
161
+
162
+ ## Future Plans
163
+
164
+ - Add option to rename only specific file type.
165
+ - Add Graphic User Interface (GUI).
166
+
167
+ ## **๐Ÿค Contributing**
168
+
169
+ We welcome contributions! Please check the [CONTRIBUTING.md](https://github.com/MFM-347/LightNamer/blob/main/CONTRIBUTING.md) for guidelines.
170
+
171
+ ## **๐Ÿ‘จโ€๐Ÿ’ป Credits**
172
+
173
+ Created and maintained by [MFM-347](https://github.com/MFM-347).
174
+
175
+ ## **๐Ÿ“œ License**
176
+
177
+ This project is licensed under the **MIT License**.
178
+
179
+ [![License MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/MFM-347/LightNamer/LICENSE)
@@ -0,0 +1 @@
1
+ from .core import LightNamer
@@ -0,0 +1,56 @@
1
+ import argparse
2
+ import logging
3
+ from pathlib import Path
4
+
5
+ from .core import LightNamer
6
+
7
+
8
+ def cli_main():
9
+ LightNamer.banner()
10
+ parser = argparse.ArgumentParser(
11
+ prog="LightNamer",
12
+ description="LightNamer is a CLI tool for renaming 100s of files in seconds.",
13
+ formatter_class=argparse.RawTextHelpFormatter,
14
+ )
15
+ parser.add_argument("base_name", type=str, help="Base name for the renamed files.")
16
+ parser.add_argument(
17
+ "directory", type=Path, help="Path to the directory containing files to rename."
18
+ )
19
+ parser.add_argument(
20
+ "-r",
21
+ "--order",
22
+ type=str,
23
+ choices=["alphabet", "new", "old"],
24
+ default="old",
25
+ help="Renaming order: \n 'alphabet' - Alphabetically\n 'new' - Newest to oldest\n 'old' - Oldest to newest (default)",
26
+ )
27
+ parser.add_argument(
28
+ "-s",
29
+ "--simulate",
30
+ action="store_true",
31
+ help="Simulate the renaming process without making actual changes.",
32
+ )
33
+ parser.add_argument(
34
+ "--case-sensitive",
35
+ action="store_true",
36
+ help="Sort files alphabetically with case sensitivity.",
37
+ )
38
+ parser.add_argument(
39
+ "--debug",
40
+ action="store_true",
41
+ help="Enable debug logging.",
42
+ )
43
+ args = parser.parse_args()
44
+
45
+ if not args.directory.exists() or not args.directory.is_dir():
46
+ logging.error(f"Error: Directory '{args.directory}' does not exist.")
47
+ exit(1)
48
+
49
+ lightnamer = LightNamer(debug=args.debug)
50
+ lightnamer.renFn(
51
+ args.base_name, args.directory, args.order, args.simulate, args.case_sensitive
52
+ )
53
+
54
+
55
+ if __name__ == "__main__":
56
+ cli_main()
@@ -0,0 +1,63 @@
1
+ import logging
2
+
3
+
4
+ class LightNamer:
5
+ def __init__(self, debug=False):
6
+ self.logger = logging.getLogger(__name__)
7
+ self._setup_logging(debug)
8
+
9
+ def _setup_logging(self, debug):
10
+ logging.basicConfig(
11
+ format="%(asctime)s - %(levelname)s - %(message)s",
12
+ level=logging.DEBUG if debug else logging.INFO,
13
+ )
14
+
15
+ @staticmethod
16
+ def banner():
17
+ banner_text = """
18
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
19
+ | <LightNamer> |
20
+ | Professional File Renamer |
21
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
22
+ """
23
+ print(banner_text)
24
+
25
+ def sortFn(self, directory, order="old", case_sensitive=False):
26
+ files = [f for f in directory.iterdir() if f.is_file()]
27
+ if order == "alphabet":
28
+ files.sort(key=lambda f: f.name if case_sensitive else f.name.lower())
29
+ elif order == "new":
30
+ files.sort(key=lambda f: f.stat().st_mtime, reverse=True)
31
+ else:
32
+ files.sort(key=lambda f: f.stat().st_mtime)
33
+ return files
34
+
35
+ def renFn(
36
+ self, base_name, directory, order="old", simulate=False, case_sensitive=False
37
+ ):
38
+ try:
39
+ files = self.sortFn(directory, order, case_sensitive)
40
+ if not files:
41
+ self.logger.warning("No files found in the directory.")
42
+ return
43
+
44
+ for index, file in enumerate(files, start=1):
45
+ new_name = f"{base_name}-{index}{file.suffix if file.suffix else ''}"
46
+ new_path = directory / new_name
47
+ counter = 1
48
+
49
+ while new_path.exists():
50
+ new_name = f"{base_name}-{index}_{counter}{file.suffix if file.suffix else ''}"
51
+ new_path = directory / new_name
52
+ counter += 1
53
+
54
+ if simulate:
55
+ self.logger.info(f"Simulated: {file.name} -> {new_name}")
56
+ else:
57
+ file.rename(new_path)
58
+ self.logger.info(f"Renamed: {file.name} -> {new_name}")
59
+
60
+ if simulate:
61
+ self.logger.info(f"Simulated renaming of {len(files)} files.")
62
+ except Exception as e:
63
+ self.logger.error(f"Error: {e}")
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.4
2
+ Name: lightnamer
3
+ Version: 1.0.0
4
+ Summary: LightNamer is a CLI tool for renaming 100s of files in seconds.
5
+ Author-email: Farhan Madni <madnifm347@outlook.com>
6
+ Project-URL: Homepage, https://github.com/MFM-347/LightNamer
7
+ Keywords: renamer,cli,auto,automation,automatic,python,opensource
8
+ Classifier: Programming Language :: Python
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Provides-Extra: dev
14
+ Requires-Dist: black; extra == "dev"
15
+ Requires-Dist: flake8; extra == "dev"
16
+ Requires-Dist: bumpver; extra == "dev"
17
+ Requires-Dist: isort; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+ # **LightNamer: CLI & Library for Auto Renaming** ๐Ÿš€
21
+
22
+ LightNamer is a **Python library and CLI tool** designed to **automate file renaming** in a given directory. It sequentially renames files using a specified **base name**, appending a numeric index while preserving the original file extension.
23
+
24
+ ## **๐Ÿ“Œ Features**
25
+
26
+ | Feature | Availability | Description |
27
+ | ------------------- | ------------ | ----------------------------------------------------------------------------- |
28
+ | **Batch Rename** | โœ” | Rename multiple files at once with a custom prefix. |
29
+ | **Sorting Options** | โœ” | Rename files in alphabetical, newest, or oldest order. |
30
+ | **Simulation Mode** | โœ” | Preview renaming changes without modifying files. No actual changes are made. |
31
+ | **Library Support** | โœ” | Use LightNamer as a module in your Python scripts for automation. |
32
+ | **Cross-Platform** | โœ” | Works seamlessly on Windows, macOS, and Linux. |
33
+
34
+ ## **๐Ÿ› ๏ธ Prerequisites**
35
+
36
+ - **Python 3.x** installed
37
+ - Basic knowledge of **command-line usage**
38
+
39
+ ### **๐Ÿ“ฆ Required Python Packages**
40
+
41
+ LightNamer requires the following package(s):
42
+
43
+ - `pyfiglet` (for CLI banner text)
44
+
45
+ To install dependencies, run:
46
+
47
+ ```sh
48
+ pip install -r requirements.txt # Use pip3 on macOS
49
+ ```
50
+
51
+ ## **โšก Installation**
52
+
53
+ ### **๐Ÿ”น Install via Pip**
54
+
55
+ To install LightNamer as a library:
56
+
57
+ ```sh
58
+ pip install lightnamer
59
+ ```
60
+
61
+ ### **๐Ÿ”น Install from Source**
62
+
63
+ To install and run the tool from the source code:
64
+
65
+ ```sh
66
+ git clone https://github.com/MFM-347/LightNamer.git
67
+ cd LightNamer
68
+ pip install .
69
+ ```
70
+
71
+ ## **๐Ÿ’ป CLI Usage**
72
+
73
+ ### **๐Ÿ“Œ Run the CLI**
74
+
75
+ ```sh
76
+ lightnamer <base_name> <directory> [-r <order>] [-s]
77
+ ```
78
+
79
+ ### **Example**
80
+
81
+ Rename files inside `C:\Users\YourName\Documents\Folder`, using "File" as the base name:
82
+
83
+ ```sh
84
+ lightnamer "File" C:\Users\YourName\Documents\Folder
85
+ ```
86
+
87
+ ### **๐Ÿ“‚ Given Directory (`C:\Docs`)**
88
+
89
+ ```
90
+ report.docx
91
+ notes.txt
92
+ summary.pdf
93
+ ```
94
+
95
+ ### **๐Ÿท๏ธ Renaming Command**
96
+
97
+ ```sh
98
+ lightnamer "Document" C:\Docs -r alphabet
99
+ ```
100
+
101
+ ### **๐Ÿ“ Output**
102
+
103
+ ```
104
+ Document-1.docx
105
+ Document-2.pdf
106
+ Document-3.txt
107
+ ```
108
+
109
+ ## **โš™๏ธ Command-Line Options**
110
+
111
+ | Option | Description |
112
+ | --------------------- | -------------------------------------------- |
113
+ | `<base_name>` | Prefix for renamed files. |
114
+ | `<directory>` | Path to folder containing the files. |
115
+ | `-r, --order <order>` | Sorting order before renaming: |
116
+ | | - `alphabet` โ†’ A-Z order |
117
+ | | - `new` โ†’ Newest to oldest |
118
+ | | - `old` โ†’ Oldest to newest (default) |
119
+ | `-s, --simulate` | Run a **simulation** without renaming files. |
120
+ | `--case-sensitive` | Sorts filenames in case-sensitive mode. |
121
+ | `--debug` | Enables debug logging. |
122
+
123
+ ## **๐Ÿ“ฆ Using LightNamer as a Library**
124
+
125
+ ### **๐Ÿ”น Installed Library Usage**
126
+
127
+ If you have installed LightNamer via `pip`, you can use it in your Python scripts as follows:
128
+
129
+ ```python
130
+ from lightnamer import renFn
131
+ from pathlib import Path
132
+
133
+ directory = Path("C:/Users/YourName/Documents/Folder")
134
+ renFn(base_name="Document", directory=directory, order="alphabet", simulate=False, case_sensitive=False)
135
+ ```
136
+
137
+ ### **๐Ÿ”น Source Code Usage**
138
+
139
+ If running directly from the cloned source repository:
140
+
141
+ ```python
142
+ from lightnamer import renFn
143
+ from pathlib import Path
144
+
145
+ directory = Path("C:/Users/YourName/Documents/Folder")
146
+ renFn(base_name="Document", directory=directory, order="alphabet", simulate=False, case_sensitive=False)
147
+ ```
148
+
149
+ ### **Sorting Files Only**
150
+
151
+ If you only need to **get sorted files** without renaming:
152
+
153
+ ```python
154
+ from lightnamer import sortFn
155
+ from pathlib import Path
156
+
157
+ directory = Path("/path/to/files")
158
+ sorted_files = sortFn(directory, order="new", case_sensitive=True)
159
+ print(sorted_files)
160
+ ```
161
+
162
+ ### **Handling Errors Gracefully**
163
+
164
+ You can wrap it in a try-except block:
165
+
166
+ ```python
167
+ try:
168
+ renFn("Example", Path("/home/user/files"), "old", False, False)
169
+ except Exception as e:
170
+ print(f"An error occurred: {e}")
171
+ ```
172
+
173
+ ## **๐Ÿงช Running Tests (For Source Code Only)**
174
+
175
+ Run all tests:
176
+
177
+ ```sh
178
+ python -m unittest discover tests
179
+ ```
180
+
181
+ ## Future Plans
182
+
183
+ - Add option to rename only specific file type.
184
+ - Add Graphic User Interface (GUI).
185
+
186
+ ## **๐Ÿค Contributing**
187
+
188
+ We welcome contributions! Please check the [CONTRIBUTING.md](https://github.com/MFM-347/LightNamer/blob/main/CONTRIBUTING.md) for guidelines.
189
+
190
+ ## **๐Ÿ‘จโ€๐Ÿ’ป Credits**
191
+
192
+ Created and maintained by [MFM-347](https://github.com/MFM-347).
193
+
194
+ ## **๐Ÿ“œ License**
195
+
196
+ This project is licensed under the **MIT License**.
197
+
198
+ [![License MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/MFM-347/LightNamer/LICENSE)
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ lightnamer/__init__.py
5
+ lightnamer/cli.py
6
+ lightnamer/core.py
7
+ lightnamer.egg-info/PKG-INFO
8
+ lightnamer.egg-info/SOURCES.txt
9
+ lightnamer.egg-info/dependency_links.txt
10
+ lightnamer.egg-info/entry_points.txt
11
+ lightnamer.egg-info/requires.txt
12
+ lightnamer.egg-info/top_level.txt
13
+ tests/test_ren.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ lightnamer = lightnamer.cli:cli_main
@@ -0,0 +1,6 @@
1
+
2
+ [dev]
3
+ black
4
+ flake8
5
+ bumpver
6
+ isort
@@ -0,0 +1 @@
1
+ lightnamer
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+
4
+ [project]
5
+ name = "lightnamer"
6
+ version = "1.0.0"
7
+ description="LightNamer is a CLI tool for renaming 100s of files in seconds."
8
+ readme = "README.md"
9
+ authors = [{ name = "Farhan Madni", email = "madnifm347@outlook.com" }]
10
+ license-files = ["LICENSE*"]
11
+ classifiers = [
12
+ "Programming Language :: Python",
13
+ "Programming Language :: Python :: 3",
14
+ ]
15
+ keywords = ["renamer", "cli", "auto", "automation", "automatic", "python", "opensource"]
16
+ requires-python = ">=3.9"
17
+
18
+ [project.optional-dependencies]
19
+ dev = ["black", "flake8", "bumpver", "isort"]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/MFM-347/LightNamer"
23
+
24
+ [project.scripts]
25
+ lightnamer = "lightnamer.cli:cli_main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,26 @@
1
+ import unittest
2
+ from pathlib import Path
3
+
4
+ from lightnamer.core import LightNamer
5
+
6
+
7
+ class TestLightNamer(unittest.TestCase):
8
+ def setUp(self):
9
+ self.lightnamer = LightNamer(debug=True)
10
+ self.test_dir = Path("test_files")
11
+ self.test_dir.mkdir(exist_ok=True)
12
+
13
+ for i in range(3):
14
+ (self.test_dir / f"file_{i}.txt").touch()
15
+
16
+ def tearDown(self):
17
+ for file in self.test_dir.iterdir():
18
+ file.unlink()
19
+ self.test_dir.rmdir()
20
+
21
+ def test_get_sorted_files(self):
22
+ files = self.lightnamer.sortFn(self.test_dir, order="alphabet")
23
+ self.assertEqual(len(files), 3)
24
+
25
+ def test_rename_files_simulation(self):
26
+ self.lightnamer.renFn("Test", self.test_dir, order="alphabet", simulate=True)