@@ -736,7 +736,17 @@ subroutine delete_file(path, err)
736
736
character (len= 512 ) :: msg
737
737
logical :: file_exists
738
738
739
+ ! Verify the file is not a directory.
740
+ if (is_directory(path)) then
741
+ ! If unable to open, assume it's a directory or inaccessible
742
+ err0 = state_type(STDLIB_FS_ERROR,' Cannot delete' ,path,' - is a directory' )
743
+ call err0% handle(err)
744
+ return
745
+ end if
746
+
739
747
! Check if the path exists
748
+ ! Because Intel compilers return .false. if path is a directory, this must be tested
749
+ ! _after_ the directory test
740
750
inquire (file= path, exist= file_exists)
741
751
if (.not. file_exists) then
742
752
! File does not exist, return non-error status
@@ -745,14 +755,6 @@ subroutine delete_file(path, err)
745
755
return
746
756
endif
747
757
748
- ! Verify the file is not a directory
749
- if (is_directory(path)) then
750
- ! If unable to open, assume it's a directory or inaccessible
751
- err0 = state_type(STDLIB_FS_ERROR,' Cannot delete' ,path,' - is a directory' )
752
- call err0% handle(err)
753
- return
754
- end if
755
-
756
758
! Close and delete the file
757
759
open (newunit= file_unit, file= path, status= ' old' , iostat= ios, iomsg= msg)
758
760
if (ios /= 0 ) then
0 commit comments