sorter improved for current working directory, needs line to be skipped
This commit is contained in:
parent
d74ab90aa9
commit
cf444b3ca3
@ -1,16 +0,0 @@
|
|||||||
import os
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
target_path = './TestFiles'
|
|
||||||
extensions = {item.split('.')[-1] for item in os.listdir(target_path) if os.path.isfile(os.path.join(target_path, item))}
|
|
||||||
# print(extensions)
|
|
||||||
|
|
||||||
for ext in extensions: # Create a folder for extension types
|
|
||||||
if not os.path.exists(os.path.join(target_path, ext)):
|
|
||||||
os.mkdir(os.path.join(target_path, ext))
|
|
||||||
|
|
||||||
# Move the files into the folder
|
|
||||||
for item in os.listdir(target_path):
|
|
||||||
if os.path.isfile(os.path.join(target_path, item)):
|
|
||||||
file_extension = item.split('.')[-1]
|
|
||||||
shutil.move(os.path.join(target_path, item), os.path.join(target_path, file_extension, item))
|
|
||||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
29
Python_Scripts/DownloadSorter/py/DownloadSorter.py
Normal file
29
Python_Scripts/DownloadSorter/py/DownloadSorter.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
def create_dir(path, extensions):
|
||||||
|
for ext in extensions:
|
||||||
|
if not os.path.exists(os.path.join(path, ext)):
|
||||||
|
os.mkdir(os.path.join(path, ext))
|
||||||
|
|
||||||
|
|
||||||
|
def move_files(target_path):
|
||||||
|
for file in os.listdir(target_path):
|
||||||
|
if os.path.isfile(os.path.join(target_path, file)):
|
||||||
|
file_extension = file.split('.')[-1]
|
||||||
|
shutil.move(os.path.join(target_path, file), os.path.join(target_path, file_extension, file))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cwd = os.getcwd()
|
||||||
|
target_path = os.path.join(cwd)
|
||||||
|
extensions = {item.split('.')[-1] for item in os.listdir(target_path) if os.path.isfile(os.path.join(target_path, item))}
|
||||||
|
# print(extensions)
|
||||||
|
|
||||||
|
# Create a folder for extension types
|
||||||
|
create_dir(target_path, extensions)
|
||||||
|
|
||||||
|
# Move the files into the folder
|
||||||
|
move_files(target_path)
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
||||||
@ -81,7 +81,6 @@ def run_command(command, path):
|
|||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main(source, target):
|
def main(source, target):
|
||||||
# Get full folder path to avoid bugs in differing OS
|
# Get full folder path to avoid bugs in differing OS
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user