| | |
File exists or not?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 198
Reputation:
Solved Threads: 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
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
•
•
Join Date: Aug 2008
Posts: 19
Reputation:
Solved Threads: 2
First, import the os module:
Then check if the path exists:
Python Syntax (Toggle Plain Text)
import os
Then check if the path exists:
Python Syntax (Toggle Plain Text)
if os.path.exists(MY_PATH_HERE): #Do something... else: #Throw an error
![]() |
Similar Threads
- Ajax javascript test if image file exists (JavaScript / DHTML / AJAX)
- File I/O Help (C)
- ofstream - detect if file has been deleted between open and close (C++)
- Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!! (Java)
- file help (C++)
- to delete contents of a text file (Java)
- PHP file handling (PHP)
- Bridge.dll error please help me here is my hijackthis log file! (Viruses, Spyware and other Nasties)
Other Threads in the Python Forum
- Previous Thread: what is strong point of python in comparison of othere language
- Next Thread: Py2exe help.
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt ansi anti apache approximation array basic beginner book builtin calculator chmod code converter countpasswordentry curved dan08 dictionaries dictionary dynamic examples excel file filename float format ftp function gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin port prime programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion recursive redirect refresh scrolledtext software ssh stamp statictext statistics string strings table terminal text textarea thread threading time tkinter tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame write wxpython






