[Python] finding a file within a directory

Discussão em 'Python' iniciado por Stack, Julho 7, 2025.

  1. Stack

    Stack Membro Participativo

    hi i have a problem with this tester, i wrote this code to open my file within a directory(topdirectory) of which in theory it would open the directory and within it will open all the files within that directory, but whenever i run it, it will open the directory but not open any of the files within it.

    topdirectory = "./POSCARTEST/"
    print (topdirectory)

    def list_files_walk (start_path):
    fulllist = []
    for root, dirs, files in os.walk(start_path):
    for file in files:
    fulllist.append(os.path.join(root, file))

    return(fulllist)

    directory_path = topdirectory

    allfiles = list(list_files_walk(directory_path))
    print(allfiles)

    Continue reading...

Compartilhe esta Página