感谢kyra和li913,我才用了kyra的方案,再次感谢 |
fortran标准没有判断文件夹的功能,你可以直接open该文件夹中一个文件 open(10,file='2003336\data.txt',iostat=i,iomsg=msg) ,配合iostat 和 iomsg就知道是否存在文件夹。 [Fortran] 纯文本查看 复制代码 program main character elname1*4, elname2*8, folder_name*15,filename*20 integer istat,istat2 real a write(elname1, '(i4)') 200 write(elname2, '(i8)') 3336 folder_name=trim(adjustl(elname1))//trim(adjustl(elname2)) inquire(file=trim(folder_name), exist=istat) write(*,*)istat if (istat) then print*, 'the file exist' else print*, 'the file no exist and will be created' istat2=system( "Md "//trim(folder_name)) end if istat2=CHDIR(trim(folder_name)) !改变当前目录到到文件夹 filename='data.txt' !打开写入数据的txt文件 open(308,file=filename,status='replace',form='formatted') write(308,*) 500 close(308) end program main |
你用intel fortran的话,可以用 Inquire(DIRECTORY="2003336",exist=b) |
捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )
GMT+8, 2024-12-23 15:30