[UP]


Manual Reference Pages  - system_remove (3)

NAME

system_remove(3f) - [M_system] call remove(3c) to remove file (LICENSE:PD)

CONTENTS

Synopsis
Description
Example
Author
License

SYNOPSIS

elemental impure function system_remove(path) result(err)

character(*),intent(in) :: path integer(c_int) :: err

DESCRIPTION

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.

EXAMPLE

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(*,*)

! 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

Expected Results:

   >  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

AUTHOR

John S. Urban

LICENSE

Public Domain


system_remove (3) July 05, 2020
Generated by manServer 1.08 from 1b12c62a-ac74-42f2-9c18-789246605a32 using man macros.