Skip to content

Commit 890a2fd

Browse files
Merge pull request #1717 from Abhinavcode13/Patch-3
Added File organizer script
2 parents 60de909 + c9be3e5 commit 890a2fd

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

File Organizer script/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# File Organizer script
2+
3+
4+
A File Organizer script is a program or script that automates the process of organizing files within a directory or multiple directories. It helps in managing and arranging files based on specific criteria, such as file type, date, name, or any custom rules.
5+
6+
The purpose of a File Organizer script is to bring structure and order to a cluttered file system by grouping files into appropriate folders or directories. This can improve file organization, make it easier to find and access files, and enhance overall file management efficiency.
7+
8+
The script typically performs tasks such as:
9+
10+
-Scanning the specified directory or directories and identifying the files present.
11+
12+
-Analyzing each file based on certain criteria, such as file extension, creation/modification date, size, or other attributes.
13+
14+
-Creating or selecting target directories or folders based on predefined rules or user-defined criteria.
15+
16+
-Moving or copying files from the source directory to the appropriate target directories based on the analysis and rules.
17+
18+
-Optionally, renaming files or performing other operations to further organize and structure the files
19+
20+
<br>
21+
22+
## Instructions 📝
23+
24+
### Step 1:
25+
26+
Save the Script: Save the script code provided earlier in a file with the desired name, such as file_organizer.py. Make sure to save it with the .py extension, indicating that it is a Python script.
27+
28+
### Step 2:
29+
30+
Customize the Script: Open the script file in a text editor and modify the source_directory and destination_directory variables with the actual paths to the source and destination directories you want to organize. You can also customize any other parameters or rules within the script to suit your specific requirements.
31+
32+
### Step 3:
33+
34+
Run the Script: Open a command prompt or terminal, navigate to the directory where the script is saved, and run the following command:
35+
36+
python file_organizer.py
37+
38+
39+
### Step 4:
40+
41+
Check the Output: The script will scan the source directory, analyze the files, and organize them based on the defined rules or criteria. The files will be moved or copied to the appropriate target directories within the destination directory. As the script processes each file, it will print a success message indicating the file's movement to the corresponding directory.
42+
43+
<br>
44+
45+
<hr>
46+
47+
> **Warning**
48+
>
49+
>Ensure that you have appropriate permissions to read files from the source directory and write files to the destination directory.
50+
51+
Remember to customize the source_directory and destination_directory variables within the script to match your specific source and destination directories.
52+
53+
When you run the script, it will organize the files within the source directory according to your defined rules, improving the overall organization and structure of the files.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
import shutil
3+
4+
def organize_files(source_directory, destination_directory):
5+
for root, dirs, files in os.walk(source_directory):
6+
for file in files:
7+
source_path = os.path.join(root, file)
8+
destination_path = os.path.join(destination_directory, file)
9+
10+
# Create destination directory if it doesn't exist
11+
os.makedirs(destination_directory, exist_ok=True)
12+
13+
# Move the file to the destination directory
14+
shutil.move(source_path, destination_path)
15+
16+
print(f"Moved {file} to {destination_directory}")
17+
18+
# Example usage: Organize files from source directory to destination directory
19+
source_directory = '/path/to/source_directory'
20+
destination_directory = '/path/to/destination_directory'
21+
22+
organize_files(source_directory, destination_directory)

0 commit comments

Comments
 (0)