0

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

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by dinilkarun
0

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
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.