Level 2: Intermediate
import glob
import shutil as sh
import os
txt = r'C:\Users\GabrielDados\Desktop\TextFiles'
img = r'C:\Users\GabrielDados\Desktop\ImgFiles'
def make_directory(txt, img):
if not os.path.exists(txt):
os.mkdir(txt)
if not os.path.exists(img):
os.mkdir(img)
make_directory(txt, img)
def move_files():
files_txt = glob.glob(r'C:\Users\GabrielDados\Desktop\arquivos\**\*.txt', recursive=True)
files_png = glob.glob(r'C:\Users\GabrielDados\Desktop\arquivos\**\*.jpg', recursive=True)
files_jpg = glob.glob(r'C:\Users\GabrielDados\Desktop\arquivos\**\*.png', recursive=True)
for file in files_txt:
sh.move(file, r'C:\Users\GabrielDados\Desktop\TextFiles')
for file in (files_png):
sh.move(file, r'C:\Users\GabrielDados\Desktop\ImgFiles')
for file in (files_jpg):
move_files()
import glob
import shutil as sh
import os
txt = r'C:\Users\GabrielDados\Desktop\TextFiles'
img = r'C:\Users\GabrielDados\Desktop\ImgFiles'
def make_directory(txt, img):
if not os.path.exists(txt):
os.mkdir(txt)
if not os.path.exists(img):
os.mkdir(img)
make_directory(txt, img)
def move_files():
files_txt = glob.glob(r'C:\Users\GabrielDados\Desktop\arquivos\**\*.txt', recursive=True)
files_png = glob.glob(r'C:\Users\GabrielDados\Desktop\arquivos\**\*.jpg', recursive=True)
files_jpg = glob.glob(r'C:\Users\GabrielDados\Desktop\arquivos\**\*.png', recursive=True)
for file in files_txt:
sh.move(file, r'C:\Users\GabrielDados\Desktop\TextFiles')
for file in (files_png):
sh.move(file, r'C:\Users\GabrielDados\Desktop\ImgFiles')
for file in (files_jpg):
sh.move(file, r'C:\Users\GabrielDados\Desktop\ImgFiles')
move_files()