Hi,

I am using a dialog box where user selects a .txt file from the local drive. The selected file along with the folder path is displayed in a textbox on the form. The user can now edit the textbox. On click on 'Proceed' button, I am saving that path.

Now if the user edits the file name(gives a file name which does not exist) the application should throw an error. How to check wheteher that file name exists in the local drive or not???.
If it does not exists then a message box with error message should be shown to the user.

Please help!....

Regards,
Dinil

Recommended Answers

All 3 Replies

First, import the os module:

import os

Then check if the path exists:

if os.path.exists(MY_PATH_HERE):
    #Do something...
else:
    #Throw an error

And os.path.isfile(name) will work for a file. Note that name is the full name, so include the full path.

Thanks a lot.... Its working.

Cheers,
Dinil

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.