列出Fortran中目录的内容 [英] Listing the contents of a directory in Fortran

查看:93
本文介绍了列出Fortran中目录的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Fortran 95中获取目录的内容?

How do I get the contents of a directory in Fortran 95?

推荐答案

如果我们将所有文件都保存在"inFiles"文件夹中,请先查找其中的文件数量,然后将其名称读入数组,检查出来:

shure if we have all the files in the 'inFiles' folder, we first find out how many are there and then we read their names into an array, check this out:

  real :: r
  integer :: i,reason,NstationFiles,iStation
  character(LEN=100), dimension(:), allocatable :: stationFileNames

  ! get the files
  call system('ls ./inFiles > fileContents.txt')
  open(31,FILE='fileContents.txt',action="read")
  !how many
  i = 0
  do
   read(31,FMT='(a)',iostat=reason) r
   if (reason/=0) EXIT
   i = i+1
  end do
  NstationFiles = i
  write(verb,'(a,I0)') "Number of station files: " , NstationFiles
  allocate(stationFileNames(NstationFiles))
  rewind(31)
  do i = 1,NstationFiles
   read(31,'(a)') stationFileNames(i)

!写(动词,'(a)')修剪(stationFileNames(i)) 做完 关闭(31)

! write(verb,'(a)') trim(stationFileNames(i)) end do close(31)

这篇关于列出Fortran中目录的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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