Creating a new Directory from a Path

so this method is crude
you have to change to the working directory before creating a sub-directory.

I would like to find a way to create a sub directory from a path

Path = “/Applications/App/jobs/client”
where “client” is a directory that may or may not exist.

i would like to be able to do some code similar to this ( but this code will not work )

[code]Dim Path As FolderITem

Path = GetFolderItem("/Applications/App/jobs/client")

if Path.Exist = False then
end if[/code]

Please advise.

You can always create a new level with

path.createAsFolder, if only client for instance, needs to be created.

Otherwise you need to travel the path from / up to client, and create the folders as they come.

It could be made into a method if you need to do that often.

How may i travel up a path ?

I will make a method to do this automatically.

Something like this may work :

[code]Public Sub CreatePath(Path as string)
dim level() as string = split(Path, “/”)

dim f as FolderItem = GetfolderItem("/"+level(0))

if not f.exists then f.CreateAsFolder

for i as integer = 1 to level.Ubound-1
f = f.child(level(i))
if not f.exists then f.CreateAsFolder

End Sub

However, in your example, it probably won’t work, because the app won’t have the permission to create a folder in /Applications.

It would work in Documents.

But you can create subfolders within the folder app, if it has already been dragged into /Applications.

i Understand.

general users will not be able to create a folder off of /Applicatons

i would have to create this path off the of the Current Users directory, where the current user would have permission to create dir’s as needed ?

by the way this is a data base using files and dirs. crude method but it does not advantages and disadvantages.

my next task will be to create this in SQL light.

Thank you for your help


I would not advise to put the sql database in the /App directory anyway. The user Documents folder would seem much more appropriate.

Wrong, two times wrong. First because you can add a folder in the Applications folder in macOS (I just checked) and this is not the place to put data in (even it it works).

ok all Thank you

Just to clarify, you can only create a folder within /Applications if you are logged into an account that has administrator privileges.

A Xojo app cannot create a new folder in /Application. It does not have the permissions. Of course, an administrator (usually the main user) can.

To play devil’s advocate, Xojo is the perfect example of distributing tons of data with the executable within a folder. But the user drags himself that folder into /Applications.

The code below in a PushButton (Xojo 2015r1), running in the IDE, allows me to create a folder in Application “as is”:

Dim f As FolderItem f = SelectFolder If f <> Nil Then MsgBox(f.Name) End If

[quote=316022:@Emile Schwarz]The code below in a PushButton (Xojo 2015r1), running in the IDE, allows me to create a folder in Application “as is”:

Dim f As FolderItem f = SelectFolder If f <> Nil Then MsgBox(f.Name) End If[/quote]

Sorry, noob question. How can you create a folder with your code?

There’s nothing in that block of code that creates a folder.

Sometimes, Emile can be difficult to decipher.

In the SelectFolder, you have a button that let you create a Folder.

It was late in the night when I wrote that. The mistake is when I do not use f.CreateAsFolder. But the answer is still valid: Xojo using SelectFolder is able to create a Folder in the Application folder.


Dim f As FolderItem f = SelectFolder If f <> Nil Then f = f.Child("MyFolder") f.CreateAsFolder End If

Creates the MyFolder in the Applications folder.

Why don’t you test what people share ?

Edit: this time, I used Xojo 2016r4.1.

This is true.

It’s a bit offtopic, but IMO, such data belongs in the Application Support folder. Special.ApplicationData.
The user documents is for documents of the user. Not a database that an application needs to work.

The OP seems intent to providing his customers access to the files. But indeed. Leaving that in Documents is a recipe for a catastrophe.

Personally, I would never put anything elsewhere than within a subfolder of ApplicationData. If I want to provide files, the app has a button that saves a copy for the customer.