[Fortran] 纯文本查看 复制代码
subroutine ClearFilesInDir(cFileDir,iFile)
use DFLib, only: GetFileInfoQQ,GetLastErrorQQ,FILE$INFO,FILE$LAST,FILE$ERROR,FILE$FIRST,ERR$NOMEM, &
ERR$NOENT,FILE$DIR,DeldirQQ,DELFILESQQ,systemQQ
Implicit None
logical DirDeleted
Character(255) cFileName
Character*(*),Intent(IN)::cFileDir !,Dirtmp
!character*(*),intent(IN)::output
integer,Intent(Out)::iFile ! 找到文件的信息
Type(FILE$INFO)::info
Integer(4)::Wildhandle,length,iresult
Wildhandle=FILE$FIRST
iFile=0
dirdeleted=systemQQ('dir '//trim(cFileDir));pause
Do WHILE (.TRUE.)
iresult=GetFileInfoQQ(trim(cFileDir),info,Wildhandle) ! //'\' 不可以加在路径名后
print*,'creation=',info.creation
print*,'lastwrite=',info.lastwrite
print*,'lastaccess=',info.lastaccess
print*,'length=',info.length
print*,'permit=',info.permit
print*,'name=',trim(info.name)
print*,'handle=',Wildhandle
print*, 'iresult=', iresult
if( (Wildhandle.eq.FILE$LAST).or.(Wildhandle.eq.FILE$ERROR) )then
select case(GetLastErrorQQ())
case(ERR$NOMEM) ! 内存不足
iFile=-1
case(ERR$NOENT) ! 碰到通配符序列尾,正常退出
return
case default
iFile=0
Return
endselect
endif
iFile=iFile+1
cFileName=trim(info.Name)
print*,trim(info.Name)
print*,trim(cFileDir)
print*,' iFile=',iFile
DirDeleted=DELFILESQQ(trim(cFileDir)//'\'//trim(info.Name))
! call WriteFileName(Trim(info.Name),output,iFile) ! WriteFileName 函数没有定义
ENDDO
DirDeleted=DeldirQQ(cFileDir)
end subroutine ClearFilesInDir