Skip to content

CSV Reader #825

@NandoJr2

Description

@NandoJr2

Hi, i'm facing a problem here.

My program can't read a csv inputed by a entry using tking package. I've tested many possibilities, and nothing yet.

from tkinter import*
from os import *
from csv import *
from shutil import *

#Criação da visualização da janela
janela=Tk()
janela.title("Copia e Cola")
janela.geometry("500x200")

#Algoritmo de procura dos arquivos
def CC():
print("bt_click")
orig=LinkO.get()
dest=LinkD.get()
arq=N_arq.get()
pref=prefx.get()
# True copiar e colar False vai recortar
copy = True
prefixo = pref
# destino Exemplo: "C:\selecionados" (lembre de criar a pasta antes)
pasta_destino = dest
pasta_origem = orig
# CSV contendo o nome dos arquivos
arquivo_csv = "testec.csv"

# pega o nome do arquivo sem a extensão
def getJustFileName(filename):
    fileName, fileExtension = os.path.splitext(filename)
    return fileName

# lista de nomes que arquivos que devem ser copiados/recortados
lista_arquivos = [];

# importa lista de arquivo CSV
with open(arquivo_csv) as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        lista_arquivos.append(prefixo + row[0])

# print(list_duplicates(lista_arquivos))

contador = 0
for root, dirs, files in os.walk(pasta_origem):
    for file in files:
        if file.endswith(".tif"):
            if (getJustFileName(file) in lista_arquivos):
                print(contador, " : ", file)
                if copy != True:
                    shutil.move(os.path.join(root, file), pasta_destino + "\\" + file)
                else:
                    shutil.copy(os.path.join(root, file), pasta_destino + "\\" + file)
                lista_arquivos.remove(getJustFileName(file))
                contador += 1

print("Arquivos não encontrados: ")
print(lista_arquivos)
pass

#Entrada e saída de dados
text0=Label(janela, text= "Arquivo CSV ")
text0.pack()
N_arq=Entry(janela)
N_arq.pack()
text1=Label(janela, text= "Origem: ")
text1.pack()
LinkO=Entry(janela)
LinkO.pack(fill= X)
text2=Label(janela, text= "Destino: ")
text2.pack()
LinkD=Entry(janela)
LinkD.pack(fill= X)
text3=Label(janela, text= "Prefixo: ")
text3.pack()
prefx=Entry(janela)
prefx.pack()

#Execução da cópia e cola
Botao1=Button(janela, text="Executar", command= CC)
Botao1.pack()

janela.mainloop()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions