listdir

jmp jeanmichel at sequans.com
Mon Sep 5 11:37:41 EDT 2016


On 09/05/2016 05:27 PM, Smith wrote:
> Hello to all,
> I wanted to know because even though the files are present on the
> directory I write input gives me "file not found".
> You can help me?
> Thank you
>
> a = input("Digita la directory dove vuoi trovare i file py:  ")
> for file in os.listdir(a):
>      if file.endswith(".py"):
>          print(file)
>      else:
>          break
> print("File not found")

Hi,

try

a = input("Digita la directory dove vuoi trovare i file py:  ")
for file in os.listdir(a):
      if file.endswith(".py"):
          print(file)

you don't want to break whenever a file does not fit the requirement, 
you want to to continue the iteration.

jm





More information about the Python-list mailing list