created new cli and added imgs

master
piyx 4 years ago committed by piyx
parent b8153059fe
commit 2da8e092a6

@ -1,3 +1,26 @@
# file-organizer
Automatically organizes files in your computer
## Usage
`python organize.py <location>`
## Example
`python organize.py C:\Users\ctrla\Downloads`
## Pics
### Before
![](imgs/before.png)
### After
![](imgs/after.png)
### Output
![](imgs/output.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

@ -0,0 +1,48 @@
import os
import sys
import shutil
import argparse
from ext import foldername
FILE_NAME = "organize.py"
EXT_NAME = "ext.py"
def organize_files(path):
path = path+'\\'
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])
# Create Folders
for ext in extns:
folder = foldername(ext)
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('.')
folder = foldername(ext)
if not folder:
continue
src = path+file
dest = path+folder+'/'+file
if not os.path.exists(dest):
shutil.move(src, dest)
print(f"Moved {file} to {folder}")
print(f"\nSUCCESS! All files organized in {path}")
try:
location = sys.argv[1]
organize_files(location)
except Exception:
print("USAGE: python organize.py <location>")

@ -1,18 +1,19 @@
import os
import shutil
import ExtensionName as ext
import ext
FileName = "FileOrganizeAutomation.py"
ExtensionModule = "ExtensionName.py"
paths = {
"Downloads" : "Downloads/",
"Desktop" : "Desktop/",
"Documents" : "Documents/",
"C Drive" : "C:/",
"D Drive" : "D:/"
"Downloads": "Downloads/",
"Desktop": "Desktop/",
"Documents": "Documents/",
"C Drive": "C:/",
"D Drive": "D:/"
}
def organizeFiles():
print("\n\nFolders...\n")
for key in paths.keys():
@ -22,7 +23,7 @@ def organizeFiles():
choice = int(input("Enter choice:"))
if choice == 1:
path = paths[input("\nEnter the folder to be organized:")]
elif choice == 2:
path = input("Enter custom path:") + '/'
print("\n")
@ -34,20 +35,21 @@ def organizeFiles():
print("Cannot make changes to system folder")
return 0
list_files = os.listdir(path)
list_extension_names = set([os.path.splitext(file)[1].strip(".") for file in list_files])
#os.path.splitext returns a tuple with file name and extension split
list_extension_names = set(
[os.path.splitext(file)[1].strip(".") for file in list_files])
# os.path.splitext returns a tuple with file name and extension split
#Eg: Filename = Hello.txt
#-----> os.path.splitext(file) returns ("Hello", ".txt")
# -----> os.path.splitext(file) returns ("Hello", ".txt")
#Create New Folders
# Create New Folders
for extension in list_extension_names:
folder_name = ext.foldername(extension)
if(folder_name == None): #Folder_name = None --> Its a folder
continue #No need to make new folder
if(folder_name == None): # Folder_name = None --> Its a folder
continue # No need to make new folder
if not os.path.exists(path + folder_name):
os.makedirs(path + folder_name)
#Move Files To Respective Folder
# Move Files To Respective Folder
for file in list_files:
if(file == FileName or file == ExtensionModule):
continue
@ -76,8 +78,5 @@ def main():
if __name__ == "__main__":
print(os.listdir("C:/Users/ctrla/Downloads/"))
main()
Loading…
Cancel
Save