private GetFileNameWithoutExtension ( string path ) : string | ||
path | string | |
Результат | string |
public static string GetFileNameWithoutExtension(string path)
{
if (path == null)
return null;
int length = path.Length;
int offset = PathInternal.FindFileNameIndex(path);
int end = path.LastIndexOf('.', length - 1, length - offset);
return end == -1 ?
path.Substring(offset) : // No extension was found
path.Substring(offset, end - offset);
}
public override void _Ready() { var levelDirectory = new Directory(); levelDirectory.Open(Game.LevelDirectory); levelDirectory.ListDirBegin(true, true); this.itemList = this.GetNode <ItemList>("ItemList"); while (true) { var file = levelDirectory.GetNext(); if (string.IsNullOrEmpty(file)) { break; } if (!file.EndsWith(".tscn")) { continue; } GD.Print($"Discovered scene: {file}"); var fileName = SystemPath.GetFileNameWithoutExtension(file); this.itemList.AddItem(fileName); this.levelList.Add(fileName); } this.itemList.Select(0); this.itemList.GrabFocus(); }