GameMaker // ENTRY

【GameMaker】分离文件路径、文件名、后缀

发布
分类 GameMaker
阅读 2 分钟 · 361 字
回应 0 条

对于Windows和MacOS的构建目标,YoYoGames官方提供了一系列用于 获取文件路径 的函数。

但本文并不叙述如何获取路径,我们假设 如果你已经有了一串路径。

theFilePath = "C:\Program Files\GameMaker\GameMaker.exe"

我们一般可以进行以下操作——

分离文件路径与文件名

function SplitPath(FilePath){
    var Pos = string_last_pos("/",FilePath) //检测最后一个/的位置
    if(string_last_pos("\\",FilePath) > Pos){
         Pos = string_last_pos("\\",FilePath) //检测最后一个\的位置
    }
    return [string_copy(FilePath,1,Pos),string_copy(FilePath,Pos+1,string_length(FilePath))]
}

var theFilePath = "C:/Program Files/GameMaker/GameMaker.exe"

filepath = SplitPath(theFilePath)

// In: show_debug_message(filepath[0])
// Out: C:/Program Files/GameMaker/
// In: show_debug_message(filepath[1])
// Out: GameMaker.exe

其中filepath为所求数组,其中包含了两个值:文件夹路径,文件名。

分离文件名与后缀

function SplitFileName(FileName){
    var Pos = string_last_pos(".",FileName) //检测最后一个.的位置
    return [string_copy(FileName,1,Pos-1),string_copy(FileName,Pos,string_length(FileName))]
}

var theFileName = "GameMaker.exe"

filenamed = SplitFileName(theFileName)

// In: show_debug_message(filenamed[0])
// Out: GameMaker
// In: show_debug_message(filenamed[1])
// Out: .exe

其中filenamed为所求数组,其中包含了两个值:文件名,后缀名。

评论

COMMENTS
0 REPLIES

还没有任何回应,成为第一个留言的人吧。

发表评论

TRANSMIT SIGNAL

支持 Markdown / 表情,礼貌交流,友善发言。