测试一个目录是否存在 [英] Test whether a directory exists or not
问题描述
我试图用Fortan90验证目录是否存在。在我发现的各个网站上:
logical :: dir_e
inquire(file ='。/ docs /。', exists = dir_e)
if(dir_e)then
write(*,*)dir exists!
else
!解决方法:它调用一个extern程序...
调用系统('mkdir docs')
结束如果
但是, inquire
返回 False
目录是否存在,如果我执行此代码两次,我收到一条错误消息
无法创建目录,文件已存在
如果我使用:
inquire(file ='。/ docs / test',存在= dir_e)
用现有文件测试,查询
返回 true
。
如何检查目录是否存在?我使用的是Ubuntu 11.04和ifort编译器。
$ b
INQUIRE(DIRECTORY = dir,EXIST = ex [,DIRSPEC = dirspec] [,ERR = label] [,IOSTAT = i-var])
我在这台机器上没有ifort,所以我无法测试它。
附录:最初发布的代码适用于gfortran。 DIRECTORY
语句适用于ifort,但不适用于gfortran。
如果需要更多信息,请检查: http: $ s I'm trying to verify that a directory exists using Fortan90. On various sites I found: However, cannot make dir, file already exists If I use: with an existing file test, How can I check for the existence of a directory? I am using ubuntu 11.04 and the ifort compiler. The following should work: I don't have ifort on this machine so I can't test it. Addendum: The code posted originally works with gfortran. The And in case for more information check: http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/win/compiler_f/lref_for/source_files/rfinquir.htm#rfinquir 这篇关于测试一个目录是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!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
inquire
returns False
whether or not the directory exists and if I execute this code twice, I get an error message
inquire(file='./docs/test', exist=dir_e)
inquire
returns true
.INQUIRE (DIRECTORY=dir, EXIST=ex [, DIRSPEC=dirspec] [, ERR=label] [, IOSTAT=i-var] )
DIRECTORY
statement works with ifort but not with gfortran.