@@ -736,7 +736,17 @@ subroutine delete_file(path, err)
736736 character (len= 512 ) :: msg
737737 logical :: file_exists
738738
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+
739747 ! 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
740750 inquire (file= path, exist= file_exists)
741751 if (.not. file_exists) then
742752 ! File does not exist, return non-error status
@@ -745,14 +755,6 @@ subroutine delete_file(path, err)
745755 return
746756 endif
747757
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-
756758 ! Close and delete the file
757759 open (newunit= file_unit, file= path, status= ' old' , iostat= ios, iomsg= msg)
758760 if (ios /= 0 ) then
0 commit comments