Specialfolder.documents

Greetings to all, I have to make a folder in the documents folder on the Mac, then make sub-folders to the first
To make the folder I used this code which works fine
var dest as folderitem
dest = Specialfolder.Documents.Child (“Myfolder”)
now i can’t make sub folders, i tried like this;
dest = Specialfolder.Documents.Child (“Myfolder / subfolder”)
but it creates another folder for me called Myfolder / subfolder
where am i wrong?
On windows I have no problems
Mario

https://documentation.xojo.com/versions/2022r2/api/files/folderitem.html#folderitem-createfolder

Try:

dest = Specialfolder.Documents.Child("Myfolder").Child("subfolder")
dest.CreateFolder
1 Like

I think you would have to create the path one item at a time:

dest = Specialfolder.Documents.Child("Myfolder")
if not dest.exists then
   dest.CreateFolder
end if
dest = Specialfolder.Documents.Child("Myfolder").Child("subfolder")
if not dest.exists then
   dest.CreateFolder
end if

I would have thought that:

dest = Specialfolder.Documents.Child("Myfolder").Child("subfolder")

would generate a NilObjectException if “Myfolder” didn’t exist and you tried to use Child on it.

2 Likes

Great, thank you all
Mario

I would tend to code it so that after creating the folderitem dest I would make a separate folderitem with a different name like subdest and then create it as subdest = dest.child(“subfolder”)

dest = Specialfolder.Documents.Child("Myfolder")
if not dest.exists then
   dest.CreateFolder
end if
Var subdest As folderitem = dest.Child("Mysubfolder")
if not subdest .exists then
   subdest.CreateFolder
end if

This way you retain both folderitems to perform additional operations with them as long as you don’t let them go out of scope.