- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does anyone know whether it's possible to create ("open") a subdirectory in the working directory of a project at runtime? What I'd like to do is, early in the program, create the subdirctory if it's non-existent. If it already exists (e.g., from an earlier execution), ignore and move on.
Output files will then opened on a path that includes this subdirctory.
I researched this and did not see any such possibility.
Output files will then opened on a path that includes this subdirctory.
I researched this and did not see any such possibility.
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if not exist (dir) mkdir (dir)
Make sure to tab this entry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
MAKEDIRQQ - see the description in the Language Reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could I please get a bit more help. Some syntax?
I find no refs for the command mkdir in any of my Visual Fortran manuals.
The line:
mkdir (Output)
and
if (.not exist. (Output)) mkdir (Output)
trigger an error:
Syntax error, found END-OF-STATEMENT when expecting one of: ( % . = =>
I find no refs for the command mkdir in any of my Visual Fortran manuals.
The line:
mkdir (Output)
and
if (.not exist. (Output)) mkdir (Output)
trigger an error:
Syntax error, found END-OF-STATEMENT when expecting one of: ( % . = =>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to recognize that concepts such as directories are external to Fortran. Therefore, there are no "commands" or "verbs" in Fortran to manipulate or enquire about directories.
However, compilers usually provide Fortran callable library routines to provide a bridge between Fortran code and operating system services. These libraries are compiler/OS specific, and are described in the compiler documentation, not in a Fortran language reference book.
However, compilers usually provide Fortran callable library routines to provide a bridge between Fortran code and operating system services. These libraries are compiler/OS specific, and are described in the compiler documentation, not in a Fortran language reference book.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The suggestion for using "mkdir" would mean that you'd have to use SYSTEMQQ or RUNQQ to executa a command line. You don't need to do that - as I wrote above, MAKEDIRQQ does exactly what you want.
USE IFPORT
if (.not. MAKEDIRQQ("subdir")) then
print *, "Failed to create subdirectory"
end if
USE IFPORT
if (.not. MAKEDIRQQ("subdir")) then
print *, "Failed to create subdirectory"
end if
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve - that's just the nudge what I needed. That was huge!
[bash]use DFLIB LOGICAL(4) result result = MakeDirQQ('mynewdir')
IF (result) THEN WRITE (*,*) 'New subdirectory successfully created' ELSE WRITE (*,*) 'Failed to create subdirectory' END IF END[/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can also use the INQUIRE statement to see if the directory exists.
logical:: L_EXISTS
character(12) :: C_DIRSPEC
C_DIRSPEC = "subdirectory"
inquire(directory=C_DIRSPEC, exist=L_EXISTS)
if(.not.L_EXISTS) then
print *,"The directory ",C_DIRSPEC," does not exist"
endif
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note that the DIRECTORY keyword to INQUIRE is our extension to the standard.

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