Código de Python - Buscador de archivos mediante expresiones regulares (nueva versión)

Imágen de perfil
Val: 712
Bronce
Ha aumentado 1 puesto en Python (en relación al último mes)
Gráfica de Python
Actualizado

Buscador de archivos mediante expresiones regulares (nueva versión)gráfica de visualizaciones


Python

Actualizado el 27 de Abril del 2024 por Antonio (75 códigos) (Publicado el 5 de Mayo del 2022)
2.397 visualizaciones desde el 5 de Mayo del 2022
Programa para buscar archivos mediante expresiones regulares.
COMANDOS:
cbd <dir> cambia el directorio base.
sch <string> realiza búsqueda por el sistema de carpetas a partir de la carpeta base.
cl realiza limpieza de pantalla.
help muestra lista de comandos.
q finaliza programa.

PARA CUALQUIER DUDA U OBSERVACIÓN, USEN LA SECCIÓN DE COMENTARIOS.
ff43
ff42
ff41

Requerimientos

LENGUAJE: Python
LIBRERÍAS Y RECURSOS: colorama

2.0

Publicado el 5 de Mayo del 2022gráfica de visualizaciones de la versión: 2.0
487 visualizaciones desde el 5 de Mayo del 2022
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from colorama import init, Fore, Back, Style
import re
 
def BMP(s):
    return "".join((i if ord(i) < 10000 else '\ufffd' for i in s))
 
def change_dir(d):
    if os.path.isdir(d):
        os.chdir(d)
        print(Fore.GREEN+"Directorio actual: {} ".format(os.getcwd())+Fore.RESET+"\n")
    else:
        print(Fore.RED+"ERROR, DIRECTORIO NO VÁLIDO"+Fore.RESET+"\n")
 
def show_dir(direc):
    global showed_dir
    if showed_dir == False:
        print(Fore.BLUE+Back.WHITE+direc+Fore.RESET+Back.RESET)
        showed_dir = True
 
def clear():
    if os.name == "posix":
        os.system("clear")
    elif os.name == "ce" or os.name == "nt" or os.name == "dos":
        os.system("cls")
 
def commands():
    print(Fore.GREEN+"---------------------------------COMANDOS---------------------------------")
    print("cbd <dir>                                           CAMBIA DIRECTORIO BASE")
    print("sch <string>                                            BÚSQUEDA CON REGEX")
    print("cl                                                       LIMPIEZA PANTALLA")
    print("q                                                       FINALIZAR PROGRAMA")
    print("help                                                MUESTRA LISTA COMANDOS")
    print("--------------------------------------------------------------------------\n"+Fore.RESET)
 
def start():
    print(Back.BLUE+"\n--------------------------FILE FINDER WITH REGEX--------------------------"+Back.RESET+"\n")
    print("Directorio actual: {} ".format(os.getcwd())+"\n")
 
def validate_entries(l):
    if len(l) > 1:
        if l[0] == 'sch' or l[0] == 'cbd':
            return l
    elif len(l) == 1:
        if l[0] == 'cl' or l[0] == 'help' or l[0] == 'q':
            return l
    else:
        return None
 
init()
 
command_list = ['cl','cbd','sch','q','help']#lista comandos
start()
 
while True:
    count = 0
    showed_dir = False
    command = validate_entries(input("Command: ").split(" "))
 
    if command is not None and command[0] in command_list:
        if command[0] == "cbd":
            command.pop(0)
            dire = (" ").join(command)
            change_dir(dire)
        elif command[0] == "q":
            clear()
            break
        elif command[0] == "cl":
            clear()
            start()
        elif command[0] == "help":
            commands()
        elif command[0] == "sch":
            command.pop(0)
            string = (" ").join(command)
            print(string)
            texto_entrada = BMP(string)
            print("BUSCANDO...\n")
            try:
                for root, folders, files in os.walk(os.getcwd()):
                    for file in files:
                        match_ = re.search(texto_entrada, file)
                        if match_:
                            show_dir(root)
                            count+=1
                            print(Fore.GREEN+'{}-'.format(count)+os.path.join(root,BMP(Fore.YELLOW+Style.DIM+file+Fore.RESET+Style.NORMAL)))
                    showed_dir = False
 
                if count == 0:
                    print(Fore.BLACK+Back.RED+"No se encontraron coincidencias con \'{}\'.".format(texto_entrada)+Fore.RESET+Back.RESET+"\n")
                else:
                    if count == 1:
                        print(Fore.BLACK+Back.GREEN+"\n1 ARCHIVO ENCONTRADO."+Fore.RESET+Back.RESET+"\n")
                    else:
                        print(Fore.BLACK+Back.GREEN+"\n{} ARCHIVOS ENCONTRADOS.".format(count)+Fore.RESET+Back.RESET+"\n")
 
            except Exception as e:
                print(Fore.BLACK+Back.RED+'ERROR: {} '.format(str(e))+Fore.RESET+Back.RESET+"\n")
 
    else:
        print(Fore.RED+"ERROR, COMANDO NO VÁLIDO"+Fore.RESET+"\n")



Comentarios sobre la versión: 2.0 (0)


No hay comentarios
 

Comentar la versión: 2.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

2.1

Actualizado el 27 de Abril del 2024 (Publicado el 26 de Junio del 2022)gráfica de visualizaciones de la versión: 2.1
1.911 visualizaciones desde el 26 de Junio del 2022
http://lwp-l.com/s7228