对于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为所求数组,其中包含了两个值:文件名,后缀名。