Passing variable to SpecialFolder?

Hello,
I’m new to Xojo.

I have tried & finished the Desktop QuickStart & Desktop Tutorial.

As an exercise, I want to create an app that listed OS Special Directories inside a list box.
Here’s the code:

[code]ListDirs.ColumnCount = 2
ListDirs.HasHeading = True
ListDirs.Heading(0) = “Key”
ListDirs.Heading(1) = “Value”

Dim dirs() As String
dirs = Array(“ApplicationData”, “Applications”, “Bin”, “Cookies”, “CurrentWorkingDirectory”, “Desktop”, “Documents”, “Etc”, “Extensions”, “Favorites”, “Fonts”, “History”, “Home”, “InternetCache”, “Library”, “Mount”, “Movies”, “Music”, “NetworkPlaces”, “Pictures”, “Preferences”, “Printers”, “RecentItems”, “SBin”, “SendTo”, “SharedApplicationData”, “SharedApplications”, “SharedDesktop”, “SharedDocuments”, “SharedFavorites”, “SharedPreferences”, “SharedStartupItems”, “SharedTemplates”, “StartupItems”, “System”, “Templates”, “Temporary”, “Trash”, “UserBin”, “UserHome”, “UserLibrary”, “UserSBin”, “Var”, “VarLog”, “Windows”)

For Each dir As String In dirs
ListDirs.AddRow dir

Dim name As FolderItem
name = SpecialFolder.dir
If name <> Nil Then
	ListDirs.Cell(ListDirs.LastIndex, 1) = name.AbsolutePath
End If	

Next[/code]

As you can see, I’m passing the variable dir to SpecialFolder method(?)
Which doesn’t work.

The question, how do you pass variable to SpecialFolder? Or if I’m doing it wrong, what’s the proper way to do this?

Second minor question is: is there a better way to assigning lots of values to an array?
I’m not a fan of the first method as in the examples in Xojo Docs.
But using the second method, Xojo doesn’t seem to allow new line in the middle of the assignment. Even using backslash.
(By the way, how do you wrap code in Xojo editor?)

You have to apply SPECIALFOLDER name explictily … (ie. SPECIALFOLDER.DESKTOP), you cannot refer to them directly using a variable name. Look into SELECT/CASE as a possible solution.

XOJO code can be wrapped to multiple lines by using the “underscore” ( _ ) character preceded by at least one space as the last character of each line segment

for i=0 to _
100 step 10
  ListDirs.ColumnCount = 2
  ListDirs.HasHeading  = True
  ListDirs.Heading(0)  = "Key"
  ListDirs.Heading(1)  = "Value"
  
  
  ListDirs.AddRow SpecialFolder.ApplicationData.Name
  ListDirs.Cell(0,1) = SpecialFolder.ApplicationData.NativePath
  ListDirs.AddRow SpecialFolder.Applications.Name
  ListDirs.Cell(1,1) = SpecialFolder.Applications.NativePath
  ListDirs.AddRow SpecialFolder.Bin.Name
  ListDirs.Cell(2,1) = SpecialFolder.Bin.NativePath

etc.

Look at XOJO Examples Folder
Applications/Xojo 2014 Release 1/Example Projects/Files/SpecialFolderPaths.xojo_binary_project

[quote=79192:@Axel Schneider][code]
ListDirs.ColumnCount = 2
ListDirs.HasHeading = True
ListDirs.Heading(0) = “Key”
ListDirs.Heading(1) = “Value”

ListDirs.AddRow SpecialFolder.ApplicationData.Name
ListDirs.Cell(0,1) = SpecialFolder.ApplicationData.NativePath
ListDirs.AddRow SpecialFolder.Applications.Name
ListDirs.Cell(1,1) = SpecialFolder.Applications.NativePath
ListDirs.AddRow SpecialFolder.Bin.Name
ListDirs.Cell(2,1) = SpecialFolder.Bin.NativePath
[/code]

etc.[/quote]
Or, “easier” to read:
dim f,Folders() as FolderItem

Folders=Array(SpecialFolder.ApplicationData,SpecialFolder.Applications,SpecialFolder.Bin, (etc.))
for i=0 to ubound(folders)
f=folders(i)

if f<>nil then 'Don’t forget to check for Nil items; each supported OS has at least one of these special folders that will return nil, so your code is going to crash if you don’t test!
ListDirs.AddRow f.Name /or, “better”, f.DisplayName
next

You can also append folders, one per line, using:
Folders.Append SpecialFolders.ApplicationData
Folders.Append SpecialFolders.Applications
…etc…

I prefer the latter to quickly find one I’d like to change, but I think it’s worse for performance.
However, I agree with the original question: if we could pass a string referencing the folder we want, we wouldn’t have to write all these SpecialFolder.Something line. Note there’s the GetFromDomainAndCode method but (1) available only on Mac and (2), has a very different format than the readable one (4 code strings).

There. Fixed that for ya. Please use the code button for source code in posts. Thx.

[code]dim f,Folders() as FolderItem

Folders=Array(SpecialFolder.ApplicationData,SpecialFolder.Applications,SpecialFolder.Bin, (etc.))
for i=0 to ubound(folders)
f=folders(i)
if f<>nil then
// Don’t forget to check for Nil items; each supported OS has at least one of
// these special folders that will return nil, so your code is going to crash if you don’t test!
ListDirs.AddRow f.Name // or, “better”, f.DisplayName
next
[/code]
You can also append folders, one per line, using:

Folders.Append SpecialFolders.ApplicationData Folders.Append SpecialFolders.Applications …etc