你有两个选择。 
简单的,先或的一个文件名,然后获得这个文件名所在的路径 
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode i = index( filename , "\" , back=.true. )
path = filename( 1 : i-1 )  
另一个选择,就是用复杂一点的方法。 
[Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode Module SHBrowseForFolder_Mod
  use Shell32
  use , intrinsic :: ISO_C_Binding , sz => c_null_char
  Implicit None
  type T_BROWSEINFO
    integer         hwndOwner
    integer         pidlRoot
    integer         pszDisplayName
    type(C_PTR)     lpszTitle
    integer         ulFlags
    integer         lpfn
    integer         lParam
    integer         iImage
  end type
  INTERFACE
    Integer Function SHBrowseForFolder( lpbi )
    !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'SHBrowseForFolderA' :: SHBrowseForFolder
      import
      type(C_PTR) :: lpbi
    End Function SHBrowseForFolder
    Integer Function SHGetPathFromIDList( pidl , pszPath )
    !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'SHGetPathFromIDListA' :: SHGetPathFromIDList
    !DEC$ ATTRIBUTES REFERENCE :: pszPath
      INTEGER , value :: pidl 
      Character(len=*) :: pszPath
    End Function SHGetPathFromIDList 
  END INTERFACE 
End Module SHBrowseForFolder_Mod
program www_fcode_cn
  implicit none
  integer :: i
  character( Len = 512 ) :: c
  i = SelectPath( c )
  if ( i /= 0 ) write(*,*) "You Select :" , trim(c)
contains
  Integer Function SelectPath( c )
    use SHBrowseForFolder_Mod
    use user32  , only : GetForegroundWindow
    character( Len = * ) , Intent( OUT ) :: c
    Type(T_BROWSEINFO) :: ofn
    Character(Len=512) :: file_spec 
    Character(Len=64)  :: cTitle
    file_spec           = sz
    cTitle              = "您好,请选择文件夹:"//sz
    SelectPath          = 0
    ofn%hwndOwner       = GetForegroundWindow()
    ofn%pidlRoot        = 0
    ofn%pszDisplayName  = 0
    ofn%lpszTitle       = c_Loc(cTitle)
    ofn%ulFlags         = 0 
    ofn%lpfn            = 0
    ofn%lParam          = 0
    ofn%iImage          = 0
    SelectPath = SHBrowseForFolder( c_loc(ofn) )
    If ( SelectPath == 0 ) return
    SelectPath = SHGetPathFromIDList( SelectPath , file_spec )
    c = file_spec( 1 : index( file_spec , sz ) - 1 )
  End Function SelectPath
end program www_fcode_cn 
 |