Merge pull request #1 from MiConnell/feature_operating_system

Feature operating system
master
piyx 4 years ago committed by piyx
commit 4fa28b0f4b

@ -1,6 +1,8 @@
import os
import sys
import platform
import shutil
import sys
from ext import foldername
FILE_NAME = "organize.py"
@ -8,30 +10,37 @@ EXT_NAME = "ext.py"
def organize_files(path):
path = path+'\\'
operating_system = platform.system()
if operating_system == "Windows": # Windows
path = path + "\\"
elif operating_system == "Darwin": # Mac
path = os.path.expanduser(path)
else:
print(f"Operating system {operating_system} not currently supported")
sys.exit(0)
if not os.path.exists(path):
print("ERROR! Invalid location")
return
files = os.listdir(path)
extns = set([os.path.splitext(file)[1].strip('.') for file in files])
extns = {os.path.splitext(file)[1].strip(".") for file in files}
# Create Folders
for ext in extns:
folder = foldername(ext)
if folder and not os.path.exists(path+folder):
os.makedirs(path+folder)
if folder and not os.path.exists(path + folder):
os.makedirs(path + folder)
# Move Files To Folders
for file in files:
if file in [FILE_NAME, EXT_NAME]:
continue
ext = os.path.splitext(file)[1].strip('.')
ext = os.path.splitext(file)[1].strip(".")
folder = foldername(ext)
if not folder:
continue
src = path+file
dest = path+folder+'/'+file
src = path + file
dest = path + folder + "/" + file
if not os.path.exists(dest):
shutil.move(src, dest)
@ -43,5 +52,6 @@ def organize_files(path):
try:
location = sys.argv[1]
organize_files(location)
except Exception:
except Exception as e:
print(f"error {e}")
print("USAGE: python organize.py <location>")

Loading…
Cancel
Save