How to name a new file created with the newdatabase statement?

This code:

newdatabase
saveas "TinyFile"

creates a new database called “Untitled” but doesn’t rename it. Why not?

What does it do if you give it a valid path? (“TinyFile” by itself is not a valid path, Panorama has no idea what folder to put the file into.)

Aha, answered my own question – this works:

newdatabase
saveas "~/TinyFile"

This created a file named TinyFile.pandb in my user folder.

Well, the saveas documentation says,

“If you want to save the new file in the same folder as the existing file, this parameter can simply be the new file name.”

which is what I thought I was doing. However, the documentation on the newdatabase statement is silent as to the location of the new database but I would have thought it logical for it to be in the currently active folder.

The point here is that this file has never been saved to disk and only exists in memory so there is no path to a folder available.

As I just mentioned in another topic, when there is no database open Panorama does not have a currently active folder. And when an unsaved file is active, there is no currently active folder. There is only a currently active folder if a database that already has been saved is the topmost window. So the saveas documentation is correct, but it is assuming that the database has already been saved at least once and you want to save another copy of the file in the same folder.

This should work but doesn’t:

newdatabase
saveas dbfolder() + "TinyFile"

In fact, no statement following the newdatabase statement is executed here.

Nevertheless, this DOES work:

newdatabase
saveas "~/TinyFile"

It’s like the problem I reported about the print statement at Close and reopen a database creates a (null) database name

I’ve reinstalled Panorama X and that has solved the problem of apparent stopping at newdatabase and print commands but I still can’t save the new database programmatically.

No, it should NOT work. The dbfolder() function returns the folder for the current database. However, you just created a new, untitled database, which does not have a folder. So dbfolder() will return an undefined value.

Actually, I just tested, and for a new untitled database, dbfolder() returns (null)/. So I suspect that probably has something to do with the problem you posted about on another thread.

The ~/ prefix is an idiom supported by macOS, it means “current user folder”. It is completely independent from the location of any database, in fact, it is not a Panorama feature, and can be used in other programs and in the shell.

OK, I’m getting it (slowly). This does the job:

local iFolder
iFolder = dbfolder()
newdatabase
saveas iFolder + "TinyFile"

Thanks again for all the input.

That works IF the folder containing the active database is the folder you want. But I don’t see how it’s different than your earlier:

newdatabase
saveas dbfolder() + “TinyFile”

You’re getting the exact same result with saveas dbfolder() + “TinyFile” and saveas iFolder + “TinyFile”, so as Jim Rea wrote:

The dbfolder() function returns the folder for the current database. However, you just created a new, untitled database, which does not have a folder. So dbfolder() will return an undefined value.

The difference is dbfolder() was run in the original file to set the iFollder variable while dbfolder() is being executed while in the new database which has never been saved and is only currently in memory so dbfolder() will return (null).