Creating folders from a plugin
Anyone knows how to create a folder with a plugin ?
Actually I was working on extending the Batch Convert plugin to export the files in a folder structure based on the score properties(*)
Creating folder is not possible by standard QML and javascript.
So I was wondering if there were other MuseScore objects able to do that.
* I was hoping that writeScore(...)
would do this if the target folder was not existing but it doesn't :-( (could perhaps be an improvement request)
* I could call an external script with this tip start another program commandline but it isn't very portable.
* Any other idea ?
Thanks
(*): For example, organise all the exports by composer: create one sub-folder by composer and place all the exports of scores from that composer in this folder:
Comments
Tried
mkdir
andmkpath
?In reply to Tried mkdir and mkpath? by Jojo-Schmitz
I called them like this:
And I got an error telling me that "mkpath is not defined" (the same for mkdir)
In reply to I called them like this:… by parkingb
You probably need to import some Qt lib, but don't ask me which
In reply to You probably need to import… by Jojo-Schmitz
QDir is not exposed to QML afaik..
Perhaps try FileIO.write?
Not sure if it creates the full path, but trying it out is free ;-)
In reply to Perhaps try FileIO.write?… by jeetee
I tried it before raising this question, and it doesn't :-(
(it throws a console message :
Could not write xxxxxxxx
)I raised also the question on Stack Overflow. With no solution until now.
I guess I will try by calling a local script.
For now my solution is to work with a platform specific script and
QProcess
Anyone could tell me how I should write
cmd /c mkdir \"d:\\misc\\temp\\foo bar8\"
to be valid under Linux, MacOS, ... (and other platforms supported by MuseScore) ?In reply to For now my solution is to… by parkingb
/bin/sh
instead ofcmd
,-c
ínstead of/c
and/
instead of\\
So
mkdir -p
if you want to create the intermediate dirs tooThe mkdir on Windows does this by default.
Same for Mac and Linux (and *BSD)
In reply to /bin/sh instead of cmd , -c… by Jojo-Schmitz
Thanks.
In reply to Thanks. by parkingb
Untested though ;-)
In reply to For now my solution is to… by parkingb
I believe that cmd.exe can deal with / nowaways, so
should work too
Edit: I checked: it does!
However: I don't think I'd like to add such platform depedant things to the Batch Convert plugin
In reply to I believe that cmd.exe can… by Jojo-Schmitz
Indeed. That's why I've made a separated branch on my repo.
To be decided later on if it is merged or not into the main branch of the plugin.
It could also be a temporary solution while waiting for
FileIO
or.writeScore
to better handle these situations (I will fill a Feature Request for both).%COMPOSER%
on Windows would need to be${COMPOSER}
on Mac and LinuxIn reply to %COMPOSER% on Windows would… by Jojo-Schmitz
Why ?
Behind it is merely a RegExp parsing for all the keywords and replacing them by the correct value ?
In reply to Why ? Behind it is merely a… by parkingb
Why? Because environment variables work different in Windows than in macOS and Linux
See
#334953: [API]Creation of folders with the PluginAPI.writeScore method
#334952: [API]Creation of folders within the FileIO objects