can't create dir path


i am trying to create a directory path “/PassSaver/Data” using the following code and nothing happens

[code] adFolder = SpecialFolder.ApplicationData

rtn = MkDir(adFolder.Name + “/PassSaver/Data”)[/code]

where adFolder is ApplicationData folder supplied by the system
/Library/Application Data/ i would like to add /PassSaver/Data folders to the “Application Data” folder.

the MkDir routine was supplied by Michel Bujardet on a previous post

[code] Shared Function MkDir(DirPath As String) As String
Dim level() as string = split(DirPath, “/”)
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

Return DirPath
End Function

i am overlooking something

please advise.

Dim level() as string = split(DirPath, "/")

Assuming that its a Unix path with a leading slash, the split function will create an array with an empty first element.

e.g. the path “/Library/Application Data” will produce an array like this:

s(0) = "" s(1) = "Library" s(2) = "Application Data"

adFolder.Name will only supply “Application Data”. It does not supply the front of the path you are seeking.

Just create the folders as you need them.

[code] dim f As FolderItem = SpecialFolder.ApplicationData

if f <> NIl Then
f = f.Child(“Pass Saver”)
if f <> Nil and not f.exists Then
end if
f = f.Child(“Data”)
if f <> Nil and not f.exists Then
end if
end if

dim myPath As String = f.NativePath[/code]

That code can be tightened up and more checks provided if you like.

i was looking for an automatic way of creating dir’s if they did not exisit using
MkDir() function…

does f.Child(“Name of Dir”) look at the front of the path… ??

The code I posted does the same thing as Michel’s function. Once you have a folderitem, you have the “front of the path”. Look at the examples that came with your Xojo copy and take a look at the LR for a better understanding of folderitems. You are thinking in terms of paths. Think in terms of children as subdirectories of where you want to go.


[code]Function MkDir(Root As FolderItem, Path As String) As FolderItem
Dim f As FolderItem = GetFolderItem(Root.NativePath, FolderItem.PathTypeNative)
Dim Folders() As String = Split(Path, If(TargetWindows, “”, “/”))

If Folders(0) = “” Then
End If

For i As Integer = 0 To Folders.Ubound
f = f.Child(Folders(i))
If Not f.Exists Then
End If

Return f

End Function
should do what you want and is xplat. Note that Path is relative to Root.

Andrews advice on a blank first level is valid, and Roger provided a specific result to your requirements.

f = SpecialFolder.ApplicationData
f.NativePath returns
/Users/davidcullins/Library/Application Support

Library does not exist or I cannot see it.
Application Support folder does not exist of i cannot see it

none of these codes are working for me. all i want to do is create 2 folders if they don’t exist. these codes either do nothing, or they create a folder named “/” or they create a compound named folder or they will create folders where i do not want them or where i cannot find them.

You don’t create several folders at the same time. That won’t work.

Create them sequentially.

[code]dim adFoldera s FolderItem = SpecialFolder.ApplicationData.child(“PassSaver”)
if not adFolder.Exists then adFolder.createAsFolder

adFolder = adFolder.child(“Data”)
if not adFolder.Exists then adFolder.createAsFolder

You really want to wrap your head around using FolderItem structures, and not outdated paths.

You also mix C or bash, or something into your code. MkDir never existed in Xojo.

When I started ages ago using this language, I spent a considerable time with the language reference open, so I can see how to do things as I go along. See

ok thank you all.