System.IO.Path.GetFileNameWithoutExtension C# (CSharp) Méthode

GetFileNameWithoutExtension() private méthode

private GetFileNameWithoutExtension ( string path ) : string
path string
Résultat 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);
        }

Usage Example

Exemple #1
0
    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();
    }
All Usage Examples Of System.IO.Path::GetFileNameWithoutExtension