- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have some FORTRAN that writes to a file, where the file path / name is specified by the user. I want to check that the user has entered:
a) a valid path / file name.
b) that the file is accessible (not read-only) if it exists.
The code should overwrite existing files and create the file if it doesn't exist.
Is there an easy way to do this, or do I have to INQUIRE on EXIST and WRITE and then variously combine the results?
Dan
a) a valid path / file name.
b) that the file is accessible (not read-only) if it exists.
The code should overwrite existing files and create the file if it doesn't exist.
Is there an easy way to do this, or do I have to INQUIRE on EXIST and WRITE and then variously combine the results?
Dan
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah...OPEN with an IOSTAT will do it, no?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why not put up a GetOpenFileName dialog box?
There are some recent threads about GetOpenFileName,
just do a search. Example code...
As mentioned in a recent thread, a dialog opened from a
console app. may appear behind the console window.
See the thread for details of a workaround if this annoys.
I attach the COMDLGER code if you need it.
HTH.
There are some recent threads about GetOpenFileName,
just do a search. Example code...
USE DFWINTY USE DFWIN IMPLICIT NONE INTEGER IRET TYPE (T_OPENFILENAME)FRED ...... CHARACTER(LEN=26)FILTER(3) CHARACTER(LEN=60)DLGTITLE CHARACTER($MAXPATH) filenamecharactervariable CHARACTER($MAXPATH) startdirectorycharactervariable ...... !* SET UP FILE SEARCH FILTERS FILTER(1) = "Your files (*.xyz)"C FILTER(2) = " *.xyz"C FILTER(3) = ""C ! set the dialog title for display in the title bar DLGTITLE = "Put your title here"C ! make Start directory a 'C string' by appending a null character STARTDIR="Some valid directory character string"//""C ! You supply the handle to the main window that will 'own' ! the dialog box FRED%HWNDOWNER = ghWnd FRED%HINSTANCE = NULL FRED%LPSTRFILTER = LOC(FILTER(1)) FRED%LPSTRCUSTOMFILTER = NULL FRED%NMAXCUSTFILTER = NULL FRED%NFILTERINDEX = 1 FRED%LPSTRFILE = LOC(filenamecharactervariable) FRED%NMAXFILE = LEN(filenamecharactervariable) FRED%LPSTRFILETITLE = NULL FRED%NMAXFILETITLE = NULL FRED%LPSTRINITIALDIR = LOC(startdirectorycharactervariable) FRED%LPSTRTITLE = LOC(DLGTITLE) ! These flags force a prompt if the user enters an ! invalid filename or path FRED%FLAGS = IOR(OFN_FILEMUSTEXIST,OFN_PATHMUSTEXIST) FRED%NFILEOFFSET = NULL FRED%NFILEEXTENSION = NULL FRED%LPSTRDEFEXT = NULL FRED%LCUSTDATA = NULL FRED%LPFNHOOK = NULL FRED%LPTEMPLATENAME = NULL FRED%LSTRUCTSIZE = SIZEOF(FRED) ! Start the get/open file dialog IRET = GETOPENFILENAME(FRED) CALL COMDLGER(IERROR)
As mentioned in a recent thread, a dialog opened from a
console app. may appear behind the console window.
See the thread for details of a workaround if this annoys.
I attach the COMDLGER code if you need it.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anthony,
A good suggestion in most cases, except mine :)
The FORTRAN is part of an OLE server application that runs online, in real-time, and largely unattended. In that respect dialog boxes are the work of the devil! They halt execution and eat resources.
I need a solution that doesn't crash, but doesn't stop either.
I solved it just using IOSTAT .NE. 0, at which point I can exit my subroutine and carry on as normal.
Dan
A good suggestion in most cases, except mine :)
The FORTRAN is part of an OLE server application that runs online, in real-time, and largely unattended. In that respect dialog boxes are the work of the devil! They halt execution and eat resources.
I need a solution that doesn't crash, but doesn't stop either.
I solved it just using IOSTAT .NE. 0, at which point I can exit my subroutine and carry on as normal.
Dan

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page