I am new programming and I am in the challenge of making an incremental file backup.
I have been based on the paradigm of object-oriented programming and I tried to work using the good practice "DRY" (Do not repeat yourself) to avoid repeating my code.
I tell you how I have distributed my code:
File_main.py classes
import glob
import os
class So:
pass
class Folder:
def set_directory(self, directory):
self.directory = directory
return directory
class File(Folder, So):
def __init__(self, directory, extension):
self.extension = self.set_extension(extension)
self.directory = self.set_directory(directory)
def set_extension(self, extension):
self.extension = extension
return extension
def buscar_archivos(self, directory, extension):
os.chdir(directory)
archivos = glob.glob(extension)
for i in range(len(archivos)):
filenames = archivos[i]
return filenames
On the other hand I have an additional file backup_incremental.py
from clases_main import File
directorio = 'D:/'
extension = '*.txt'
# Objeto de Instancia
search_archivos = File(directorio, extension)
archivos = search_archivos.buscar_archivos(directorio, extension)
for i in range(len(archivos)):
print(archivos)
I would like to know how I can search for the txt files in that directory and display the names when I run the file backup_incremental.py , when I do the for in this file, the names are repeated for some reason, I would also like to start learning to show data in json if you can include me some advice on this I will also thank you immensely.
Edit: I've updated the code to not print as much
Greetings and thanks!