Created
February 19, 2023 01:30
-
-
Save estevaofon/b639f3909c90312ec6517c2dfcb4ee5b to your computer and use it in GitHub Desktop.
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
import os | |
import shutil | |
def main(): | |
# Diretório a ser analisado | |
directory = '.' | |
# Nome do script atual | |
current_script = os.path.basename(__file__) | |
# Dicionário para armazenar pastas com extensões | |
extensions = {} | |
# Percorre cada arquivo no diretório | |
for filename in os.listdir(directory): | |
# Ignora o script atual e pastas | |
if filename == current_script or os.path.isdir(filename): | |
continue | |
# Ignora arquivos sem extensão | |
if '.' not in filename: | |
continue | |
# Obtém a extensão do arquivo | |
file_extension = filename.split('.')[-1] | |
# Cria uma pasta para a extensão, se ainda não existir | |
if file_extension not in extensions: | |
if not os.path.exists(file_extension): | |
os.mkdir(file_extension) | |
extensions[file_extension] = file_extension | |
# Move o arquivo para a pasta da extensão | |
shutil.move(filename, f"{file_extension}/{filename}") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment