叶子的离开 发表于 2015-8-30 14:40:52

【叶子出品】FreeBasic 根据文件路径获取 目录、文件名、后缀

本代码采用 crt 实现,为什么呢?因为FB的标准库太坑了,除了混乱的类型以外,也会明显增量程序,并且性能很差。

上代码~

Function GetPathFloder(sInPath As ZString Ptr, sOutPath As ZString Ptr) As Integer
        Dim rstr As ZString Ptr = StrRChr(sInPath, 92)
        If rstr Then
                memcpy(sOutPath, sInPath, rstr - sInPath)
                Return -1
        EndIf
End Function

Function GetPathFileName(sInPath As ZString Ptr, sOutPath As ZString Ptr) As Integer
        Dim rstr As ZString Ptr = StrRChr(sInPath, 92)
        If rstr Then
                strcpy(sOutPath, rstr + 1)
                Return -1
        EndIf
End Function

Function GetFileFileType(sInPath As ZString Ptr, sOutPath As ZString Ptr) As Integer
        Dim rstr As UByte Ptr = StrRChr(sInPath, 46)
        If rstr Then
                For i As Integer = 1 To strlen(rstr)
                        sOutPath = toupper(rstr)
                Next
                Return -1
        EndIf
End Function

Function GetPathFileType(sInPath As ZString Ptr, sOutPath As ZString Ptr) As Integer
        Dim TmpPath As ZString Ptr = malloc(MAX_PATH)
        If GetPathFileName(sInPath, TmpPath) Then
                If GetFileFileType(TmpPath, sOutPath) Then
                        free(TmpPath)
                        Return -1
                EndIf
        EndIf
        free(TmpPath)
End Function

admin 发表于 2015-8-31 15:34:23

crt 是什么?

叶子的离开 发表于 2015-9-6 10:19:36

admin 发表于 2015-8-31 15:34
crt 是什么?

c runtime。
对于windows来说,一般指 msvcrt.dll
页: [1]
查看完整版本: 【叶子出品】FreeBasic 根据文件路径获取 目录、文件名、后缀