Hello guys,
I have a program created that opens a program and execute it as well.

For example:

filename = raw_input('Input a valid NAPS filename -> ')

I put my file helloworld.naps (my file extension)
And it execute smoothly.

Now my question is, how to verify the user input if there is a .naps file extension in their file.
If they have not, then there will be an error that displays 'You have entered an invalid filename'. I got the logic but I dunno how to code it.

Well, you have

>>> import os
>>> filename = "foo/bar/baz/qux.naps"
>>> name = os.path.basename(filename)
>>> name
>>> base, extension = os.path.splitext(name)
>>> base
>>> extension

and also

>>> os.path.exists(filename) # check if file exists
# or
>>> os.path.isfile(filename) # check if a regular file with that name exists

Edited 4 Years Ago by Gribouillis

I tried this code of yours and put some if-elif statements and its now fully working.
I'm really thankful for the quick response sir. Soon if I quite learn more about python, I'll contribute to this community. ^__^

This question has already been answered. Start a new discussion instead.