Is there a way to allow the user to navigate through a directory to select a file?

0

Basically, what I want to achieve is that the user can select a file interactively (as in the "browse" windows)

    
asked by guille 30.07.2017 в 02:46
source

2 answers

1

I do not know if you want to do it graphically or not, but I tell you how to do it in TUI:

import os

dirs = os.scandir(".") # «.» Hace referencia al directorio actual.
dirs = list(dirs) # dirs es un iterador, lo convertimos a una lista.

for x in range(len(dirs)):
    print(x, ".", dirs[x])

dir = int(input("\nSelecciona un directorio: "))

if dir < len(dirs):
    print("Has elegido:", dirs[dir])
    
answered by 30.07.2017 в 03:04
1

There are libraries that can cover this task, such as Tkinter .

Here is a simple example of how to implement it:

from tkinter.filedialog import askopenfilename
archivo = askopenfilename()
    
answered by 30.07.2017 в 02:59