jpcgandre
jpcgandre

Reputation: 1505

Rename file in Fortran 77

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

RENAME(old name, new name)

or something like:

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

Thanks

Upvotes: 4

Views: 2942

Answers (2)

Bálint Aradi
Bálint Aradi

Reputation: 3812

You can use the modFileSys library for that. In contrast to non-standard compiler extensions, it can be compiled with any Fortran 2003 compiler and can be used an all POSIX compatible systems. You could also check for errors, if needed:

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

Upvotes: 2

John
John

Reputation: 16007

I think you nailed it with the first one:

CALL RENAME('oldname','newname')

More here. And here.

Upvotes: 2

Related Questions