How to access files in a plugin's subfolder using FileIO?

• Jun 26, 2023 - 20:14

The only way I've been able to do it is by settings source to the full file path, including C:/Users/xxxx. There has to be an easier way? I've tried subfolder/file, /subfolder/file, ./subfolder/file, and filePath + /subfolder/file all to no avail


Comments

I use filePath like this:

function showDocu()
{
filo.source = filePath + "/TabRing.html";
tout = filo.read();
if (tout == "") tout = "Documentation file not found.";
popInfo.text = tout;
tout = "";
infoWin.visible = true;
}

with: FileIO { id: filo }

I haven't set its value anywhere in the plugin but it points to the plugin's root folder.

In reply to by XiaoMigros

Not sure what you mean.
My definition is after plugin global properties:

// Score Map

property var mIX : [] // Map index
property var mMez : []
property var mTick : []
property var mStr : []
property var mFret : []
property var mFace : [] // Face value length
property var mMIDI : [] // MIDI note value for 2nds detection
property var mTup : [] // Tuplet factor or 0:Not a tuplet
property var mTie : [] // 0:No tie, 1:Tie forward, -1:Tie back
property var mVox : [] // Voice 0-3 within each Part
property var mPlay : [] // Play flag: =Play, =Silent
property var mOnT : [] // Ontime‰
property var mLen : [] // Length‰
property var mOnTk : [] // Ontime in ticks
property var mLnTk : [] // Length in ticks
property var mDoll : [] // $ string codes
property var mArt : [] // Articulations

// File Handle

FileIO { id: filo }

onRun:
{
checkTAB();
}

I don't know if you still need a solution, but this is how I do:

readonly property var librarypath: { {
        var f = Qt.resolvedUrl("somefile.json");
        f = f.slice(8); // remove the "file:" added by Qt.resolveUrl and not understood by the FileIO API
        return f;
    }
}

FileIO {
    id: libraryFile
    source: librarypath
    onError: {
        console.log(msg);
    }
}

This will look for a file somefile.json in the plugin's folder.

Do you still have an unanswered question? Please log in first to post your question.