-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into Main_AmitM_Feature_CustomEncryptionDecryptio…
…n_21Jan
- Loading branch information
Showing
20 changed files
with
745 additions
and
397 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
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,75 @@ | ||
import argparse | ||
import os | ||
import logging | ||
import shutil # For moving files | ||
|
||
def main(): | ||
try: | ||
args = parse_arguments() | ||
check_directory(args.directory_path) | ||
|
||
setup_logging(args.verbose) | ||
|
||
organize_directory(args.directory_path) | ||
# Catch any exceptions that may occur | ||
except Exception as e: | ||
print(e) | ||
|
||
def parse_arguments(): | ||
# Parse the arguments from cli, order is irrelevant | ||
parser = argparse.ArgumentParser(description="Organize files in a directory based on their extensions.") | ||
parser.add_argument("directory_path", type=str, help="Path of the directory to be organized") # Required argument | ||
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output") # Optional argument | ||
return parser.parse_args() | ||
|
||
def check_directory(directory_path): | ||
if not os.path.isdir(directory_path): | ||
raise ValueError(f"'{directory_path}' is not a valid directory.") | ||
|
||
if not os.listdir(directory_path): | ||
raise ValueError(f"'{directory_path}' is an empty directory!") | ||
|
||
if not os.access(directory_path, os.W_OK): | ||
raise ValueError(f"'{directory_path}' is not writable.") | ||
|
||
def setup_logging(verbose): | ||
log_level = logging.INFO if verbose else logging.WARNING | ||
log_format = "%(message)s" | ||
logging.basicConfig(level=log_level, format=log_format) | ||
|
||
def organize_directory(directory_path): | ||
categories = { | ||
"Music": (".mp3", ".wav", ".flac", ".m4a", ".aac", ".ogg", ".oga", ".wma", ".mid",), | ||
"Videos": (".mp4", ".avi", ".mkv", ".mpeg", ".wmv", ".vob", ".flv", ".mov", ".3gp", ".webm",), | ||
"Source Files": (".py", ".c", ".cpp", ".java", ".js", ".cs", ".html", ".css", ".php", ".json", ".xml", ".sql", ".db",), | ||
"Executables": (".exe", ".msi", ".sh", ".bat", ".apk", ".jar", ".deb", ".run", ".bin", ".dmg", ".iso",), | ||
"Pictures": (".jpg", ".jpeg", ".png", ".gif", ".bmp", ".svg", ".webp", ".psd", ".ai", ".ico",), | ||
"Documents": (".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".txt", ".md", ".odt", ".ods", ".odp", ".csv", ".rtf",), | ||
"Compressed": (".zip", ".rar", ".tar", ".gz", ".7z", ".bz2", ".xz", ".z", ".lz",), | ||
"Torrents": (".torrent",), | ||
} | ||
|
||
for category, extensions in categories.items(): | ||
# Check if there are files with matching extensions for this category | ||
files_with_extension = [file for file in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, file)) | ||
and os.path.splitext(file)[1].lower() in extensions] | ||
|
||
if files_with_extension: | ||
# Create a folder for this category if it doesn't exist | ||
category_folder = os.path.join(directory_path, category) | ||
if not os.path.exists(category_folder): | ||
os.makedirs(category_folder) | ||
logging.info(f"Creating '{category}' folder.") | ||
else: | ||
logging.info(f"'{category}' folder already exists, reusing.") | ||
|
||
for file in files_with_extension: | ||
source_path = os.path.join(directory_path, file) | ||
dest_path = os.path.join(category_folder, file) | ||
shutil.move(source_path, dest_path) | ||
logging.info(f"Moved '{file}' to '{category}' folder.") | ||
|
||
print("Organizing files complete!") | ||
|
||
if __name__ == "__main__": | ||
main() |
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
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
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
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
speedtest==0.0.1 | ||
speedtest_cli==2.1.3 | ||
speedtest_cli |
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
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,90 @@ | ||
import os | ||
import shutil | ||
|
||
|
||
def main(): | ||
dir_path = input("Enter the directory path of the files: ") | ||
|
||
try: | ||
print( | ||
"Organising your files into [ images - music - video - executable - archive - torrent - document - code - design files]" | ||
) | ||
for filename in os.listdir(dir_path): | ||
absname = os.path.join(dir_path, filename) | ||
# Check if files are images and you can add more extensions | ||
if filename.lower().endswith( | ||
(".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm") | ||
): | ||
# If images folder doesn't exist then create new folder | ||
if not os.path.exists("images"): | ||
os.makedirs("images") | ||
shutil.move(absname, "images") | ||
|
||
# Check if files are music and you can add more extensions | ||
elif filename.lower().endswith( | ||
(".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw") | ||
): | ||
# If music folder doesn't exist then create new folder | ||
if not os.path.exists("music"): | ||
os.makedirs("music") | ||
shutil.move(absname, "music") | ||
|
||
# Check if files are videos and you can add more extensions | ||
elif filename.lower().endswith((".webm", ".mp4")): | ||
# If video folder doesn't exist then create new folder | ||
if not os.path.exists("video"): | ||
os.makedirs("video") | ||
shutil.move(absname, "video") | ||
|
||
# Check if files are executables | ||
elif filename.lower().endswith((".exe", ".msi", ".deb", "dmg")): | ||
# If executables folder doesn't exist then create new folder | ||
if not os.path.exists("executables"): | ||
os.makedirs("executables") | ||
shutil.move(absname, "executables") | ||
|
||
# Check if files are archive files | ||
elif filename.lower().endswith((".rar", ".tar", ".zip", ".gz")): | ||
# If archive folder doesn't exist then create new folder | ||
if not os.path.exists("archives"): | ||
os.makedirs("archives") | ||
shutil.move(absname, "archives") | ||
|
||
# Check if files are torrent files | ||
elif filename.lower().endswith((".torrent",)): | ||
# If torrent folder doesn't exist then create new folder | ||
if not os.path.exists("torrent"): | ||
os.makedirs("torrent") | ||
shutil.move(absname, "torrent") | ||
|
||
# Check if files are documents | ||
elif filename.lower().endswith((".txt", ".pdf", ".docx", "doc")): | ||
# If documents folder doesn't exist then create new folder | ||
if not os.path.exists("documents"): | ||
os.makedirs("documents") | ||
shutil.move(absname, "documents") | ||
|
||
# Check if files are code files | ||
elif filename.lower().endswith((".py", ".php", ".html", ".css", ".js")): | ||
# If code folder doesn't exist then create new folder | ||
if not os.path.exists("code"): | ||
os.makedirs("code") | ||
shutil.move(absname, "code") | ||
|
||
# Check if files are design files | ||
elif filename.lower().endswith((".psd", ".ai")): | ||
# If design folder doesn't exist then create new folder | ||
if not os.path.exists("design-files"): | ||
os.makedirs("design-files") | ||
shutil.move(absname, "design-files") | ||
|
||
except OSError: | ||
print("Error happened ...... try again") | ||
finally: | ||
# When script is finished clear screen and display message | ||
os.system("cls" if os.name == "nt" else "clear") | ||
print("Finished organising your files") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
colorama==0.4.5 | ||
comtypes==1.1.11 | ||
Pillow==10.0.1 | ||
Pillow==10.2.0 | ||
pypiwin32==223 | ||
pyttsx3==2.90 | ||
pywin32==304 | ||
|
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
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,29 @@ | ||
import os | ||
|
||
|
||
def main(): | ||
img_types = ["jpg", "png", "jpeg"] | ||
dir_path = input("Enter the directory path of the images: ") | ||
|
||
for i, f in enumerate(os.listdir(dir_path)): | ||
absname = os.path.join(dir_path, f) | ||
img_type = absname.split(".")[-1] | ||
|
||
if img_type in img_types: | ||
while True: | ||
newname = input(f"Enter the new name for {f} (without extension): ") | ||
newname = "{}.{}".format(newname, img_type) | ||
new_absname = os.path.join(dir_path, newname) | ||
if not os.path.exists(new_absname): | ||
os.rename(absname, new_absname) | ||
break | ||
else: | ||
print( | ||
"A file with this name already exists. Please enter a different name." | ||
) | ||
|
||
print("Done renaming images.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 @@ | ||
Pillow |
Oops, something went wrong.