Copy Error

Am I doing something incorrectly? I have this in my Open event handler hoping to create a new folder and copy a file from my Resources folder to it. I also change “CopyFileTo” to “CopyTo” and back with my getting the same error that the folder items can’t be found. The code I’m using is…

[code]Using Xojo.IO
Dim sourceFile As FolderItem
Dim destFile As FolderItem
Dim f as FolderItem

f = SpecialFolder.SharedDocuments.Child(“Main”).Child(“SubD”)
f.CreateAsFolder

sourceFile = SpecialFolder.Resources.Child(“db.sqlite”)

destFile = SpecialFolder.SharedDocuments.Child(“Main”).Child(“SubD”).Child(sourceFile.Name)
sourceFile.CopyFileTo(destFile)
[/code]

Does the folder “Main” exist? Do you have write privileges to it?

Hi Wayne!

Yes, and it is a writable folder. The strange thing is it worked initially, then I uninstalled the app and re-installed it, then got error. Same thing happened to my beta-test. I’m baffled.

Does your source file “db.sqlite” exist?

Don’t chain your folderitems:

dim SourceFile as folderitem = SpecialFolder.Resources if SourceFile <> nil and SourceFile.exists then SourceFile = SourceFile.Child("something") if SourceFile <> nil and SourceFile.exists then SourceFile = SourceFile.Child("something else")

Hi Graham,
Yes, it exists too. The error states it can’t find the folders I want to create. Both folders are user writable, and worked before I uninstalled the app. I can place the db in the SpecialFolders themselves, but cannot create the child.

Thanks Beatrix. I see that. I commented one out and still got the error.

Can it be a permissions problem? I usually get error -5000 when the folder can’t be written to on macOS. You don’t say which OS you are working with.

Beatrix I’m using Mojave. The error is an error 0, Nil…

It’s like I stated, I can copy the db there, and write to it, but can’t create the child folders.

iCloud?

Translocation?

May add some more validation checks and print out errors eg:

[code]Dim sourceFile As FolderItem
Dim destFile As FolderItem
Dim f as FolderItem

f = SpecialFolder.SharedDocuments.Child(“Main”)
if not f.Exists then
MsgBox "Main not found at " + f.NativePath
return
end if

f = f.Child(“SubD”)
if not f.Exists then
//Ensure you are only creating the directly once
f.CreateAsFolder()
end if
if not f.Exists then
MsgBox "Source folder not found at " + f.NativePath
return
end if

sourceFile = SpecialFolder.Resources.Child(“db.sqlite”)
if not sourceFile.Exists then
MsgBox "Source file not found at " + sourceFile.NativePath
return
end if

destFile = f.Child(sourceFile.Name)
if destFile.Exists then
//already there - skip
else
sourceFile.CopyFileTo(destFile)
end if[/code]

Graham, I’ll give it a try and let you know. Thank you all!