Copyfile can't find file to be copied

Hopefully(?) I’m missing something simple and obvious here. I want to copy an image file, rename it, and put the renamed copy in a different location. Here’s the core code:

copyfile "blank.jpg","Grad students/2022-2023 grads/"+newname+".jpg"

“blank.jpg” is in the same folder as the database that calls the procedure, but I’m getting “CopyFile error: the file “blank.jpg” doesn’t exist” even though it clearly does. So am I indeed missing something simple and obvious?

Possibly the variable newname does not already exist. Try

let newname="FormalPhoto"

If that was the problem then that error would be reported, not that the file doesn’t exist.

The actual problem is that the copyfile statement is not associated with a database, so the path doesn’t default to the current database. You must explicitly specify the entire path, like this:

copyfile dbinfo("folder","")+"blank.jpg",...

I’m not sure about your second parameter. Where is the Grad students folder? If it is in the same folder as the database, then I think you’ll also need to add dbinfo( to that parameter also. The way you have written it the folder would have to be at the root level of the hard drive, which I doubt is the case.

I think this might be wrong. I just verified using copyfile to copy a file in the same Documentation folder as the database running this procedure.

copyfile "Bee.mp3","Bee2.mp3"

This created Bee2.mp3 just below the original Bee.mp3 in the same folder. No full path required. I noticed it took some time for the Finder to update and show the file was actually there.

Jim, I was using the format as specified by the Panorama help reference for files and folders:

" Paths Relative to the Current Database
If a path doesn’t begin with the / or ~ characters, it is relative to the location of the current database. For example, the path mylogo.gif specifies that the file mylogo.gif is in the same folder as the current database. The path artwork/signature.png specifies that the file signature.png is located in the folder artwork, which is located in the same folder as the current database."

Ok, I stand corrected. I looked in the copyfile documentation and there was no mention of being able to use database relative paths. I’m pretty sure that database relative paths didn’t work in copyfile in Panorama 6. But looking at source control, this has always worked in Panorama X, the code in question hasn’t changed since 2013.

So, I can only conclude that this statement from the original post is false, and the file clearly does NOT exist. Or the database you are running isn’t where you think it is (maybe there is more than one copy?)

So when I was trying to figure this out, I selected and these files (i.e., the database, the image, and the Grad students folder) as a group from Dropbox to a new location on my computer – no change. But I forgot to move them back to Dropbox, so I couldn’t work on this until this morning. Strangely enough, when I selected and moved them back to Dropbox (but a slightly different location), the procedure could now find the image file. So probably not a Panorama problem, but makes me wonder about the computer…