How to list files in a folder where there is a specific file with python

1

I would like to know how I can with pyhton list all the files in a folder that contains a specific file so that if that file is moved to another folder I list the files of the new folder where it is located. Thanks!

    
asked by Lucia 02.05.2016 в 14:36
source

1 answer

1
import os

scanned = 0

infected = "prueba.txt" 

#Busca en todas los directorios de "C:/" el archivo "prueba.txt"
y cuando lo encuentra hace un print del directorio del archivo
for root, dirs, files in os.walk('C:/'):
    scanned = scanned + 1
    for file in files:
        if infected in file:
            print((root + "/" + file))
            print("Archivos total escaneados: " + str(scanned))
    
answered by 01.06.2016 в 04:20