Seb*_*ian 6 fortran fortran90 intel-fortran
我正在尝试使用Fortan90验证目录是否存在.在我发现的各种网站上:
logical :: dir_e
inquire(file='./docs/.', exist=dir_e)
if ( dir_e ) then
write(*,*) "dir exists!"
else
! workaround: it calls an extern program...
call system('mkdir docs')
end if
Run Code Online (Sandbox Code Playgroud)
但是,inquire返回False目录是否存在,如果我执行此代码两次,我收到一条错误消息
无法制作dir,文件已经存在
如果我使用:
inquire(file='./docs/test', exist=dir_e)
Run Code Online (Sandbox Code Playgroud)
使用现有文件测试,inquire返回true.
如何检查目录的存在?我正在使用ubuntu 11.04和ifort编译器.
以下应该有效:
INQUIRE (DIRECTORY=dir, EXIST=ex [, DIRSPEC=dirspec] [, ERR=label] [, IOSTAT=i-var] )
Run Code Online (Sandbox Code Playgroud)
我在这台机器上没有ifort所以我无法测试它.
附录:最初发布的代码与gfortran一起使用.该DIRECTORY声明适用于ifort但不适用于gfortran.
小智 5
Fortran标准95,2003和2008没有指定,如何查询应该处理目录.根据我在Linux下的经验,gfortran将它们视为文件,而ifort则不然.目录语句是ifort的专有功能,因此应该避免使用.
最安全的是测试所述目录中的文件.