hi,
I’m trying to open a specific application folder using the following code:
[code]Dim f as FolderItem
f = GetFolderItem("/Users/myusername/Library/Application Support/MyApp/Export")
If f <> Nil and f.Directory then
f.launch
End If[/code]
The above code works on Windows but not on Mac OSX.
thanks
Is that your ACTUAL code?
It should be
and better done in two parts
[quote]if Specialfolder.ApplicationSupport.child(“MyApp”).exists then
f = Specialfolder.ApplicationSupport.child(“MyApp”).child(“Export”)
if f.exists then
[/quote]
Hi Jeff,
That code is part of a function in my application, is in the Action function of a pushbutton. The SpecialFolder works for a system folder however I want the user to also select a non-system folder.
thanks
In a project where I have application data, I used a global property (in a Module) to store a reference (FolderItem) to my folder in SpecialFolder.ApplicationSupport
: i can access directly to that folder contents (but I check the FolderIte against Nil and Exists, in case
/to avoid troubles).
So that isn’t your actual code.
The example above shows a hard coded path to a folder that is valid for Windows file system, but not for OSX.
What does your actual code look like?
Does it even reach the .launch line in debug, and have you checked that the folder .exists ?
Hi Jeff,
That is the actual code. I haven’t used the SpecialFolder object just hard coded the folder path. I replaced the if statement with :
If f <> Nil and f.Exists then
and that doesn’t open the folder window and no error message is displayed.
In another part of my application I use the SelectFolderDialog object to get and save the folder path to the database.
If I cannot hard code a folder path, how can the path from SelectFolderDialog be set with the FolderItem object?
thanks
You can set the path with InitialDirectory … if i understand you right.
Dim dlg As New SelectFolderDialog
dlg.InitialDirectory = SpecialFolder.Documents
Ok. This is my last shot at asking… does the .launch line actually get executed?
I say the path you show above is wrong and therefore the folder doesnt exist, and so the program doesnt even try.
Have you run this in debug mode?
So you assign this value to a folderitem and .launch that?
Right now, I dont know if we are looking at a badly created folderitem which doesnt exist, or a failure to launch an actual valid folderitem
Add these lines
[code]if f.exists then
msgbox “Exists”
else
msgbox “does not exist”
end if
If f.exists and f.Directory then
msgbox “launching now…”
f.launch
End If[/code]
f = GetFolderItem("/Users/myusername/Library/Application Support/MyApp/Export", FolderItem.PathTypeShell)
On Windows it is not important. On Mac it is.
You could do better than that, though :
f = specialfolder.ApplicationData.child("myApp").child("Export")
And it will work on all machines, not simply yours. As well as Mac and Windows.
http://documentation.xojo.com/index.php/SpecialFolder
Hi Michael,
You are right, your code works. Thank you very much. By specifying the FolderItem.PathTypeShell parameter (which is the POSIX path), the launch command opened successfully the Finder window.
cheers!
[quote=300926:@Serafim Tsioumas]Hi Michael,
You are right, your code works. Thank you very much. By specifying the FolderItem.PathTypeShell parameter (which is the POSIX path), the launch command opened successfully the Finder window.
[/quote]
Note that space character should normally be escaped with a backslash :
f = GetFolderItem("/Users/myusername/Library/Application\\ Support/MyApp/Export", FolderItem.PathTypeShell)
http://documentation.xojo.com/index.php/FolderItem.ShellPath
hard coding a path is a road to troubles
using backslash (\) will not be a good idea too (especially if you want to go crossplatform)
IMHO.
I agree, I’ll use a variable.
f = SpecialFolder.Applications.child("myApp").child("Export")
http://documentation.xojo.com/index.php/Specialfolder