-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
4 changed files
with
190 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,69 @@ | ||
{ | ||
"EXTENSIONS": { | ||
"IMAGE_EXT": [ | ||
".jpg", | ||
".jpeg", | ||
".png", | ||
".gif", | ||
".webp", | ||
".psd", | ||
".tiff", | ||
".tif", | ||
".bmp", | ||
".heif", | ||
".svg" | ||
], | ||
"AV_EXT": [ | ||
".mp4", | ||
".mov", | ||
".wmv", | ||
".avi", | ||
".avchd", | ||
".flv", | ||
".mkv", | ||
".ogg", | ||
".mpeg", | ||
".M4P", | ||
".M4V", | ||
".mp3", | ||
".wav", | ||
".aac" | ||
], | ||
"DOCUMENT_EXT": [ | ||
".pdf", | ||
".docx", | ||
".pptx", | ||
".xlsx", | ||
".ppt", | ||
".pages", | ||
".csv", | ||
".txt", | ||
".zip" | ||
], | ||
"CODING_EXT": [ | ||
".py", | ||
".cpp", | ||
".swift", | ||
".html", | ||
".css", | ||
".js", | ||
".jsx", | ||
".java", | ||
".c", | ||
".v", | ||
".r", | ||
".asm" | ||
], | ||
"ALL_FOLDERS_CREATED": [ | ||
"Photos", | ||
"Documents", | ||
"AudioVideo", | ||
"CodingFiles", | ||
"Others", | ||
"ZipFiles", | ||
"Folders", | ||
"Others", | ||
"fos" | ||
] | ||
} | ||
} |
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,83 @@ | ||
import os | ||
import json | ||
from progressBar import ProgressBar | ||
|
||
|
||
class FileSort: | ||
def __init__(self): | ||
with open("extensions.json", "r") as data: | ||
data = json.load(data)['EXTENSIONS'] | ||
self.IMAGE_EXT = data['IMAGE_EXT'] | ||
self.AV_EXT = data["AV_EXT"] | ||
self.DOCUMENT_EXT = data['DOCUMENT_EXT'] | ||
self.CODING_EXT = data['CODING_EXT'] | ||
self.ALL_FOLDERS_CREATED = data['ALL_FOLDERS_CREATED'] | ||
|
||
self.PATH = os.getcwd() | ||
self.files_in_directory = os.listdir() | ||
self.ALL_FOLDERS_CREATED = list( | ||
map(lambda x: f"{self.PATH}/{x}", self.ALL_FOLDERS_CREATED)) | ||
|
||
def createDirectory(self, folderName: str, file: str): | ||
if folderName not in self.files_in_directory: | ||
os.mkdir(f"{self.PATH}/{folderName}") | ||
self.files_in_directory.append(f"{folderName}") | ||
|
||
os.rename(f"{self.PATH}/{file}", f"{self.PATH}/{folderName}/{file}") | ||
|
||
def basic_sort(self, desc=''): | ||
for file in self.files_in_directory: | ||
root, ext = os.path.splitext(f"{self.PATH}/{file}") | ||
|
||
if root in self.ALL_FOLDERS_CREATED and ext == '': | ||
continue | ||
|
||
elif ext in self.IMAGE_EXT: | ||
self.createDirectory(folderName="Photos", file=file) | ||
|
||
elif ext in self.DOCUMENT_EXT: | ||
self.createDirectory(folderName="Documents", file=file) | ||
|
||
elif ext in self.AV_EXT: | ||
self.createDirectory(folderName="AudioVideo", file=file) | ||
|
||
elif ext in self.CODING_EXT and root != f"{self.PATH}/main": | ||
self.createDirectory(folderName="CodingFiles", file=file) | ||
|
||
elif ext == '' and root not in self.ALL_FOLDERS_CREATED: | ||
self.createDirectory(folderName="Folders", file=file) | ||
|
||
else: | ||
self.createDirectory(folderName="Others", file=file) | ||
|
||
pgBar = ProgressBar(desc=desc) | ||
pgBar.createProgressBar() | ||
print("Your files have been sorted!") | ||
|
||
def deep_sort(self, desc=''): | ||
self.basic_sort(desc=desc) | ||
self.PATH = self.PATH + "/Documents" | ||
self.files_in_directory = os.listdir(self.PATH) | ||
for file in self.files_in_directory: | ||
root, ext = os.path.splitext(f"{self.PATH}/{file}") | ||
|
||
if ext == '': | ||
continue | ||
|
||
elif ext == '.pdf': | ||
self.createDirectory(folderName="PDF_FILES", file=file) | ||
|
||
elif ext in ['.docx', '.pages']: | ||
self.createDirectory(folderName="WORD_FILES", file=file) | ||
|
||
elif ext[0:len(ext)-1] == '.ppt': | ||
self.createDirectory(folderName="PRESENTATIONS", file=file) | ||
|
||
elif ext[0:len(ext)-1] == '.xls': | ||
self.createDirectory(folderName="SPREADSHEETS", file=file) | ||
|
||
elif ext == '.zip': | ||
self.createDirectory(folderName="ZIP_FILES", file=file) | ||
|
||
else: | ||
self.createDirectory(folderName="OTHER_FILES", file=file) |
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,26 @@ | ||
from argparse import ArgumentParser, Namespace | ||
from fos import FileSort | ||
import sys | ||
|
||
parser = ArgumentParser() | ||
fos = FileSort() | ||
|
||
parser.add_argument('-b', '--basic', | ||
help="Sorts your files into basic folders namely Photos, AudioVideo, Documents, CodingFiles, Folders, Others", | ||
action="store_true", | ||
) | ||
parser. add_argument('-d', '--deep', | ||
help="Further sorts the folders into sub categories based on extensions", | ||
action='store_true', | ||
) | ||
|
||
args: Namespace = parser.parse_args() | ||
|
||
if args.deep: | ||
fos.deep_sort("Doing a deep sort for yout files...\n") | ||
|
||
elif args.basic: | ||
fos.basic_sort("Doing a basic sort for your files...\n") | ||
|
||
else: | ||
parser.print_help(sys.stderr) |
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,12 @@ | ||
from tqdm import tqdm | ||
from time import sleep | ||
|
||
|
||
class ProgressBar: | ||
def __init__(self, desc): | ||
self.desc = desc | ||
|
||
def createProgressBar(self): | ||
from tqdm import tqdm | ||
for _ in tqdm(range(100), desc=self.desc): | ||
sleep(.01) |