如何解决Godot 引擎在网络驱动器、UNC 路径上创建文件夹
如何使用 Godot 引擎在网络驱动器上创建新目录?
使用以下代码,我可以在本地路径内的编辑器和构建模式下成功创建目录和文件,但无法在网络驱动器上创建目录。
虽然我无法在网络驱动器路径中创建目录(Godot 目录错误返回:20),但我仍然可以成功创建文件。
extends Node
onready var bEditorMode: bool = not OS.has_feature("standalone")
onready var sMainPath: String = "res://" if bEditorMode else OS.get_executable_path().get_base_dir()
var iTestCases: Array = [1,2,3,4,5,6]
func _ready() -> void:
print("Running in ","editor" if bEditorMode else "build"," mode...\nMain path set as: ",sMainPath)
for _test_case in iTestCases:
match _test_case:
1: print("1. Accessing the main path. Result: ",Open_Main_Path())
2: print("2. Creating test dir. Result: ",Create_Test_Dir(sMainPath,"TestDir"))
3: print("3. Creating test file. Result: ",Create_Test_File(sMainPath,"TestFile","txt"))
4: print("4. Creating test file inside the test dir. Result: ",Create_Test_File(sMainPath.plus_file("TestDir"),"txt"))
5: print("5. Creating test dir using cmd. Result: ",Create_CMD_Test_Dir("TestCmdDir"))
6: print("6. Creating test file inside the cmd test dir. Result: ",Create_Test_File(sMainPath.plus_file("TestCmdDir"),"TestCmdFile","txt"))
_: print("Test case: ",_test_case," out of bounds")
func Open_Main_Path() -> int: return Directory.new().open(sMainPath)
func Create_Test_Dir(_dir_path: String,_dir_name: String) -> int:
var _result: int = -1
if Open_Main_Path() == OK: _result = Directory.new().make_dir(_dir_path.plus_file(_dir_name))
return _result
func Create_Test_File(_file_path: String,_file_name: String,_file_extension: String) -> int:
var _result: int = -1
if Open_Main_Path() == OK:
var _path: String = _file_path.plus_file(_file_name) + str("." if not _file_extension.begins_with(".") else "",_file_extension)
var _file: File = File.new()
_result = _file.open(_path,_file.WRITE) ; _file.close()
return _result
func Create_CMD_Test_Dir(_dir_name: String) -> int: return OS.execute("cmd.exe",["/C mkdir" + str(" ",_dir_name)])
编辑器结果:
本地结果:
网络结果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。