Check if file exists

Dan Laüt's icon

Never guessed that creating a routine to check whether a file exists would be such a hassle. Should have taken 10 minutes, but took a day. None of the 'file' objects in Max has such a function, except perhaps the filemanager object, but the workings of that one are quite mysterious. There is no reference doc, no settings in the inspector other than the basics, no info in the sidebar, and the help file does not list an 'exist' function. I wrestled with putting a java class pulled from the web into an mxj object, but gave up after an hour of failures. At the end of the day, still nothing. I dropped it from my mind. That usually helps a lot in situations like that. And indeed, later that night, I had a vision, which I hereby attach for the good of all. Hope it saves you some time.

file_exists.js
text/javascript 0.18 KB
Simple JS function to check whether a file exists.

11OLSEN's icon

you should have searched the forum. this question came up a lot of times. I'm still using the [absolutepath] solution. That object outputs "notfound" if file or folder does not exist.

Andy Maskell's icon

Here is one way to see if a file exists using the folder object:

11OLSEN's icon

Yes, but that's totally inefficient and one has to split the file from the path to use that + it creates a symbol for every file in that folder.

Andy Maskell's icon

@11Olsen Ah yes! You posted your suggestion whilst I was still testing mine so I didn’t see it! Ha ha.