-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c1d5e13
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# OrgFile | ||
|
||
A simple python code for automatically organizing your messy files into different folders. I mainly use this program to organize my file in my Downloads Folder since it can become very messy. | ||
|
||
# Installation (Linux) | ||
|
||
1. Download and Extract `orgfile` to a directory | ||
2. Enter in your terminal `cd ~` | ||
3. Enter in your terminal `mkdir -p bashes/scripts/py` (if it still doesn't exists) | ||
4. Paste the `orgfile` inside the `bashes` folder | ||
5. Paste the `orgfile.py` inside the `bashes/scripts/py` folder. | ||
6. Enter in your terminal `echo "export PATH=$PATH:~bashes" >> ~/.bashrc` | ||
|
||
|
||
# Usage | ||
|
||
1. Go to your messy folder | ||
2. type `orgfile` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
python ~/bashes/scripts/py/orgfile.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import os | ||
import shutil | ||
|
||
# You can change this for your desired output folder | ||
mainOutputFolder = "organize/" | ||
|
||
# This is not really necessary since we discovered the files dynamically | ||
# However, if you want to stop the "[!} {ext} is currently not supported" message | ||
# You can add the file extensions here | ||
files = { | ||
".py": [], | ||
".exe": [], | ||
".pdf": [], | ||
".cpp": [], | ||
".h": [], | ||
".json":[], | ||
} | ||
|
||
# This function will move the files to the specified folder | ||
def moveFiles(ext, filename): | ||
""" | ||
Move the files to the specified folder | ||
""" | ||
|
||
# For every file in the list of files with the same extensionile | ||
for file in files[ext]: | ||
# Try to move the file to the specified folder | ||
try: | ||
shutil.move(file, f"{mainOutputFolder}{filename}/{file}") | ||
print(f"[/] Moved {file} to {filename}/{file}") | ||
|
||
# Otherwise, permission might be denied | ||
except: | ||
|
||
# If you are getting this error, you need to be sure that no other program is using the file. | ||
print(f"[!] Permission might be denied for \"{file}\"... Trying to Continue") | ||
|
||
if __name__ == "__main__": | ||
|
||
# Get the current directory | ||
dirs = os.scandir() | ||
|
||
# For every file in the current directory# | ||
for file in dirs: | ||
|
||
# Try to get the index of the last dot in the file name | ||
try: | ||
ext_idx = file.name.rindex('.') | ||
|
||
# If there is no dot, then we'll just assume it is a folder | ||
except: | ||
print(f"[!] Found a possible Folder: {file.name}") | ||
continue | ||
|
||
# Get the file extension | ||
ext = file.name[ext_idx:].lower() | ||
|
||
# Try to add the file to the list of files with the same extensiony | ||
try: | ||
files[ext].append(file.name) | ||
|
||
# If the extension is not specified in the files dictionary, then we'll add it | ||
except: | ||
print(f"[!] {ext} is currently not supported") | ||
print(f"[!] Supporting \"{ext}\"") | ||
files[ext] = [] | ||
files[ext].append(file.name) | ||
|
||
# Try to create the main output foldery | ||
try: | ||
os.mkdir(f"{mainOutputFolder}") | ||
print(f"[/] Created {mainOutputFolder}") | ||
|
||
# If it fails, then we'll just use the current directory | ||
except: | ||
# If it continuously fails, there might be a permission issuee | ||
mainOutputFolder = "" | ||
print(f"[!] Can't Create {mainOutputFolder}... Trying to continue using the current directory") | ||
|
||
# For every file extension in the files dictionary | ||
for key,value in files.items(): | ||
|
||
# If there are files with the same extension# | ||
if len(value) >= 1: | ||
|
||
# Create a folder with the name of the extension | ||
try: | ||
os.mkdir(f"{mainOutputFolder}{key[1:]}") | ||
print(f"[/] Created {key[1:]}") | ||
except: | ||
printf(f"[!] {key[1:]} already exists") | ||
|
||
# then move the files to the specified folder. | ||
moveFiles(key, key[1:]) | ||
else: | ||
continue |