Rename file in Fortran 77

Is there a way to rename a file in fortran 77? eg:

RENAME(old name, new name)

or something like:

call system("rename" // trim(old name) // " " // trim(new name)) 

thanks

+4
source share
2 answers

I think you nailed it first:

CALL RENAME('oldname','newname')

More details here . And here .

+2
source

You can use the modFileSys library for this . Unlike non-standard compiler extensions, it can be compiled with any Fortran 2003 compiler and can be used by all POSIX compatible systems. You can also check for errors:

program test
  use libmodfilesys_module
  implicit none

  integer :: error

  ! Renaming with error handling
  call rename("old.dat", "new.dat", error=error)
  if (error /= 0) then
    print *, "Error happened"
  end if

  ! Renaming without explicit error handling, stops the program
  ! if error happens.
  call rename("old2.dat", "new2.dat")

end program test
+2
source

All Articles