测试一个目录是否存在 [英] Test whether a directory exists or not

查看:193
本文介绍了测试一个目录是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用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:

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

However, inquire returns False whether or not the directory exists and if I execute this code twice, I get an error message

cannot make dir, file already exists

If I use:

inquire(file='./docs/test', exist=dir_e)

with an existing file test, inquire returns true.

How can I check for the existence of a directory? I am using ubuntu 11.04 and the ifort compiler.

解决方案

The following should work:

INQUIRE (DIRECTORY=dir, EXIST=ex [, DIRSPEC=dirspec] [, ERR=label] [, IOSTAT=i-var] )

I don't have ifort on this machine so I can't test it.

Addendum: The code posted originally works with gfortran. The DIRECTORY statement works with ifort but not with gfortran.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆