Cabbage Logo
Back to Cabbage Site

Save filepath to a text file

Hi everyone,
I simply try to catch the filepath I am chossing in a directory open dialog and try saving it to a text file - without luck yet.

Here is my code so far dereived from the examples “cabbageFileOpcodes”:

instr 1000

SFileToOpen, kTrigger cabbageGetValue "openFile"

SFile1 cabbageGetFilename SFileToOpen
cabbageSet kTrigger, "label1", sprintfk("text(\"File name: %s\")", SFile1) 
SFile2 cabbageGetFileExtension SFileToOpen
cabbageSet kTrigger, "label2", sprintfk("text(\"File extension: %s\")", SFile2) 
SFile3 cabbageGetFileNoExtension SFileToOpen
cabbageSet kTrigger, "label3", sprintfk("text(\"File without extension: %s\")", SFile3) 
SFile4 cabbageGetFilePath SFileToOpen
cabbageSet kTrigger, "label4", sprintfk("text(\"File path: %s\")", SFile4) 
ktrig metro 1
if ktrig == 1 then
Sgetter = sprintfk("text(\"File path: %s\")", SFile4)
strset 1,  Sgetter
String strget  1
fprints "my111.sco", String, String


What I end up with in my txt file is:
text("File path: ")

But the path is not saved. Strange thing is I can see it in the GUI of cabbage.

thanks for any hints.

Is this not because strset is i-time only. The file path is not known at i-time. Are you sure you need to use strset, I work with strings all the time and in 20 years have only once ever needed to use it. What are you trying to do?

@rorywalsh maybe it is not the right way, I just want to navigate to a folder and save the path to a text file.

Try this:

form caption("File Opcodes") size(470, 280), guiMode("queue") colour(58, 110, 182), pluginId("MPre")
filebutton bounds(180, 12, 142, 39), channel("openFile"), corners(5) text("Open", "Open"), populate("*")


sr = 44100
nchnls = 1
0dbfs = 1 

instr 1000

    SFileToOpen, kTrigger cabbageGetValue "openFile"

    if kTrigger == 1 then
        event "i", 1001, 0, 0

instr 1001

    ;this instrument is only called when openFile contains a file name
    SFile chnget "openFile"
    fprints "/Users/rwalsh/Documents/my111.sco", SFile, SFile

i1000 0 z
1 Like

Works like a charm @rorywalsh thank you!