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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值