本帖最后由 shrine 于 2017-9-14 21:29 编辑 kyra 发表于 2017-9-14 07:47 终于搞定了,谢谢 |
本帖最后由 shrine 于 2017-9-14 14:07 编辑 kyra 发表于 2017-9-14 07:47 好的 |
本帖最后由 shrine 于 2017-9-13 21:53 编辑 kyra 发表于 2017-9-13 20:42 RENAMEFILEQQ( 'a.txt', 'b.txt' ) 在这个程序中,是不是RENAMEFILEQQ( stInfo.Name, 'b.txt' )? |
那就不知道为啥了。反正我这里是OK的。 你试试自己操作字符串改名吧。 |
截图或拍照 |
本帖最后由 shrine 于 2017-9-13 19:38 编辑 kyra 发表于 2017-9-13 18:43 不行,输出的还是整个文件名 我的ivf是2017 |
你的IVF可能版本比较早,没有导入这个函数。你需要手动导入。 [Fortran] 纯文本查看 复制代码 Program www_fcode_cn Implicit None integer :: n External ToDoOneFile call DoWithWildcard( "j:\123\*" , ToDoOneFile , n ) write(*,*) '共',n,'个文件' End Program www_fcode_cn !Subroutine ToDoOneFile( cFile , iLoop ) ! Character( Len = * ) , Intent( IN ) :: cFile ! Integer , Intent( IN ) :: iLoop ! Write( * , * ) '第',iLoop,'个文件:',cFile !End Subroutine ToDoOneFile Subroutine ToDoOneFile( cFile , iLoop ) use , intrinsic :: ISO_C_Binding INTERFACE FUNCTION GetShortPathName(lpszLongPath,lpszShortPath,cchBuffer) import integer :: GetShortPathName ! DWORD !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'GetShortPathNameA' :: GetShortPathName !DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpszLongPath character*(*) lpszLongPath ! LPCSTR lpszLongPath !DEC$ ATTRIBUTES REFERENCE, ALLOW_NULL :: lpszShortPath character*(*) lpszShortPath ! LPSTR lpszShortPath integer cchBuffer ! DWORD cchBuffer END FUNCTION END INTERFACE Character( Len = * ) , Intent( IN ) :: cFile Integer , Intent( IN ) :: iLoop integer :: k character(len=512) :: sFile k = GetShortPathName( trim(cFile)//c_null_char , sFile , len(sFile) ) Write( * , * ) '第',iLoop,'个文件:', sFile(:k) End Subroutine ToDoOneFile recursive Subroutine DoWithWildcard(cWildcard,CallBack,iTotal) !// 下一句代码,如果是 Compaq 或 Digital,需改为 Use DFLib Use IFPort , only : GetFileInfoQQ , GetLastErrorQQ , FILE$INFO , FILE$LAST , FILE$ERROR , FILE$FIRST , ERR$NOMEM , ERR$NOENT , FILE$DIR Implicit None !character(len=256) a integer::zl Interface Subroutine CallBack( cFile , iLoop ) Character( Len = * ) , Intent( IN ) :: cFile Integer , Intent( IN ) :: iLoop End Subroutine CallBack End Interface Character( Len = * ) , Intent( IN ) :: cWildcard Integer , Intent( OUT ) :: iTotal Type (FILE$INFO) :: stInfo Integer(4) :: iWildhandle , iLength , iRet iWildhandle = FILE$FIRST iTotal = 0 Do While (.TRUE.) iLength = GetFileInfoQQ( cWildCard , stInfo , iWildhandle ) If (( iWildhandle == FILE$LAST) .OR.( iWildhandle == FILE$ERROR )) then Select Case (GetLastErrorQQ()) Case (ERR$NOMEM) !//内存不足 iTotal = - 1 return Case (ERR$NOENT) !//碰到通配符序列尾 return Case Default iTotal = 0 return End Select End If iLength = index( cWildcard , "\" , .true. ) If ( ( stInfo%permit.AND.FILE$DIR ) == 0 ) then call CallBack( cWildcard(:iLength)//trim(stInfo%Name) , iTotal + 1 ) iTotal = iTotal + 1 !zl=len(stInfo.Name) !write(*,*)stInfo.Name !write(*,*)zl Else if(stInfo%Name(1:1) /= "." ) then call DoWithWildcard( cWildcard(:iLength)//trim(stInfo%Name)//"\"//cWildcard(iLength+1:) , CallBack , iTotal ) !!!文件夹,递归 endif End If End Do End Subroutine DoWithWildcard |
捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )
GMT+8, 2024-11-23 22:01