回 帖 发 新 帖 刷新版面

主题:求在visual fortran中调用api函数getfiletime的例子

求在visual fortran中调用api函数getfiletime的简单例子
谢谢!
我想通过文件的最后修改时间来查找特定文件
据说fortran本身不能实现
需要调用api函数getfiletime
各位大侠帮帮忙啊!

回复列表 (共1个回复)

沙发

如果是 Visual Fortran 的话,两个方法

1. 用扩展函数

Program Main
  Use IFPORT
  USE IFPORT
  CHARACTER(80) file
  TYPE (FILE$INFO) info
  INTEGER(4) handle, iRes
  INTEGER(2) iyr, imon, iday, ihr, imin, isec
  file = 'c:\ntldr'
  handle = FILE$FIRST
  iRes = GETFILEINFOQQ(file, info, handle)
  Call UNPACKTIMEQQ(info%lastwrite, iyr, imon,iday, ihr, imin, isec)
  Write(*,*) iyr, imon, iday , ihr, imin, isec
End Program Main

2. 用 API

Program Main
  Use Kernel32
  Integer iHandle , iRes
  TYPE (T_SECURITY_ATTRIBUTES) :: stSec
  TYPE (T_FILETIME) :: stCreate , stModify , stAccess
  TYPE (T_SYSTEMTIME) :: stSysTime
  iHandle = CreateFile( "C:\ntldr" , GENERIC_READ     , FILE_SHARE_READ , stSec , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , 0 )
  iRes = GetFileTime( iHandle , stCreate , stAccess , stModify )
  iRes = FileTimeToLocalFileTime( stModify , stModify )
  iRes = FileTimeToSystemTime( stModify , stSysTime )
  write(*,*) stSysTime%wYear , stSysTime%wMonth , stSysTime%wDay , stSysTime%wHour , stSysTime%wMinute , stSysTime%wSecond
End Program Main

我来回复

您尚未登录,请登录后再回复。点此登录或注册