system_remove(3f) - [M_system_FILE_SYSTEM] call remove(3c) to remove file (LICENSE:PD)
Synopsis
Description
Examples
Author
License
elemental impure function system_remove(path) result(err)
character(*),intent(in) :: path integer(c_int) :: err
Fortran supports scratch files via the OPEN(3c) command; but does not otherwise allow for removing files. The system_remove(3f) command allows for removing files by name that the user has the authority to remove by calling the C remove(3c) function.
Sample program:
program demo_system_remove use M_system, only : system_remove character(len=*),parameter :: FILE=MyJunkFile.txt integer :: ierr write(*,*)BEFORE CREATED //FILE call execute_command_line(ls -l //FILE) write(*,*)Expected Results:! note intentionally causes error if file exists open(unit=10,file=FILE,status=NEW) write(*,*)AFTER OPENED //FILE call execute_command_line(ls -l //FILE) write(*,*)
write(10,(a)) This is a file I want to delete close(unit=10) write(*,*)AFTER CLOSED call execute_command_line(ls -l //FILE) write(*,*)
ierr=system_remove(FILE) write(*,*)AFTER REMOVED,IERR call execute_command_line(ls -l //FILE) write(*,*)
end program demo_system_remove
> BEFORE CREATED MyJunkFile.txt > ls: cannot access MyJunkFile.txt: No such file or directory > > AFTER OPENED MyJunkFile.txt > -rw-r--r-- 1 JSU None 0 Nov 19 19:32 MyJunkFile.txt > > AFTER CLOSED > -rw-r--r-- 1 JSU None 32 Nov 19 19:32 MyJunkFile.txt > > AFTER REMOVED 0 > ls: cannot access MyJunkFile.txt: No such file or directory
John S. Urban
Public Domain
Nemo Release 3.1 | system_remove (3m_system) | March 07, 2025 |