Check between excel and windows lists

Asked

Viewed 24 times

-1

good afternoon. I’m developing a program that has 3 stages:
1st Stage: Read a certain directory on Windows that contains multiple subfolders and return me a listing with the name of all the files that exist inside (in this case, they are photo names);
Stage 2: Read an excel spreadsheet that has a range with name of several photos;
Stage 3: Result in a list of file names that appear in the excel file (in step 2), but are not within the Windows directory (step 1), that is, the photo does not exist.

Stage 1 and Stage 2 rotate as below

Step 1

pasta='C:\Users\55419\Google Drive\área de trabalho' 
caminhoAbsoluto = os.path.abspath(pasta)

for _, _, arquivo in os.walk(caminhoAbsoluto):  
    listafotos = [w.upper() for w in arquivo]

Step 2

wb=openpyxl.load_workbook('CONFERÊNCIA DE FOTOS - teste programa.xlsx') 
sheet=wb['Planilha1'] #inserir o nome da aba a ser analisada
letracol=get_column_letter(sheet.max_column)
ultimalinha=(sheet.max_row)
maxcol=letracol+str(ultimalinha)
print(maxcol)
tuple(sheet['M1':'M440'])  #inserir o valor de maxcol encontrado
for rowOfCellObjects in sheet['M1':'M440']: #inserir o valor de maxcol encontrado
    for cellObj in rowOfCellObjects:
        if cellObj.value != None:
            listabase=cellObj.value

Step 3

lista_fotos_ausentes=[x for x in listabase if x not in listafotos]
print(lista_fotos_ausentes)

I don’t need you to print the result of steps 1 and 2, only 3. However, I will insert here answer of the respective steps to facilitate the visualization...

Step 1
inserir a descrição da imagem aqui

Step 2
inserir a descrição da imagem aqui

Step 3
inserir a descrição da imagem aqui

I tried to use the following code too and it didn’t help

lista_fotos_ausentes = list(set(listabase) - set(listafotos))

Does anyone have any idea what I can do to get him to return the name of the photo that’s not on the photo list? The ideal would also be for the answer of step 3 to be in a single column, as in step 2.

Thanks in advance!!! =)

1 answer

0

I think I get it: your base list is a string and not a list, switch to listabase.split("\n") that I think will work.

  • Hi @Arthurbacci. I ended up using append to add each iteration item to my base list. It worked, everyone stayed as a string within a single list. Thanks for the comment!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.