Get a bang from [text] when file not found?

    Jan 13 2022 | 11:50 pm
    Hi! I'm looking for ways to read a file with a specific name, or write that file if it is missing.
    If I send a "read myfile.txt" message to [text], I get a red error in the Max window that the file was not found. Helpful, but not useful for my purpose. If I could somehow get a bang when the file is not found, I could use that to kick off another part of the patch that might create the file or do something else.
    Any thoughts? Thanks!

    • Jan 14 2022 | 9:59 am
      Here are a couple of solutions. Using the "error" object seems to be the best, but a bit fussy. This seems like a reasonable feature request.
    • Jan 14 2022 | 1:36 pm
      I use absolutepath for that since max 4
      but prefer to use absolute paths, instead of just read and write
    • Jan 14 2022 | 3:34 pm
      absolutepath is a clean solution (unless we need the same outside the search path)
    • Jan 14 2022 | 3:52 pm
      absolute path to absolutepath object does not care about max search paths
    • Jan 14 2022 | 4:59 pm
      well, you usually have your max patch in the search path, but then maybe you might want to have samples or preferences files somewhere in the system.
      then, like shown in your screenshot, you need to provide the full path. a standalone made by somebody else might not find such a path.
    • Jan 14 2022 | 10:52 pm
      Thanks for the good suggestions.
      Source Audio, I tried implementing the solution in your screenshot, but when I try send "write test.txt" to [text], i get "error -1 creating file"
      This post suggests the error means "directory does not exist." Where would [text] try to write the file by default? Do I need to do something to allow permissions? I would like this to be able to work in a standalone on any random system.
    • Jan 15 2022 | 11:32 am
      My advice is to allways provide full path. And yes - it is complicated because of permissions. If you create new patch without saving it to disk, insert text object and send it write message, then file could be saved anywhere, depending on last opened file location, or even path to which in applications folder might not allow you to write anything there, again depending on security settings of the system. When max patch is saved to disk and restarted, write message should try to write file next to the patcher. But I don't use this simple write messages since quite a while, and have no interest in finding out in each new Max and OS version what should be if, in first place when it comes to standalones -------- This kind of stuff has been discussed so many times on the forum, including auto path creation using thispatcher, maxsendapppath and so on. No need to repeat this over and over. There are safe places suggested to create folders and write files, like in Documents and similar.
    • Jan 15 2022 | 4:29 pm
      Thanks! Yeah, this thread has gone a bit offtopic from the original question, which is resolved.
      I think in my case it's trying to write in the windows Program Files folder which does have some permissions restrictions. I will do some forum searching to see about various options, especially things that will work safely in standalones. The things you mention above are definitely solutions to consider.