Dmitry Bubnenkov
Dmitry Bubnenkov

Reputation: 9859

QML: how to get file baseName

How I can extract file baseName from full file URL?

FileDialog
    {
        id: fileDialog
        title: "Oooopen"
        onAccepted:
        {
        console.log(fileUrl)    
        }

    }

fileUrl do not have properties like baseName I tried to googling, but without success

Upvotes: 3

Views: 4312

Answers (1)

You could define your own basename function

function basename(str)
{
    return (str.slice(str.lastIndexOf("/")+1))
}


FileDialog
{
    id: fileDialog
    title: "Oooopen"
    onAccepted:
    {
        console.log(basename(fileUrl.toString()))    
    }
}

Upvotes: 5

Related Questions