SpecialFolder
From Xojo Documentation
Used to get a FolderItem for a specific folder or directory managed by the host operating system.
Methods | ||
|
Usage
result = SpecialFolder.FolderName
Part | Type | Description |
---|---|---|
result | FolderItem | If successful, a FolderItem for the specified folder/directory.
SpecialFolder returns Nil if the call is unsuccessful. |
FolderName | String literal | The requested folder or directory.
See the table in the Notes section for the possible values. |
Folder Names and Paths
These names and paths are from Windows 10 (64-bit), macOS 10.12.5 and Mint 18.1 (64-bit). The paths may differ slightly on other operating systems and versions.
FolderName | Windows | macOS | Linux |
---|---|---|---|
AppleMenu
|
\Users\UserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ | Nil | Nil |
ApplicationData | \Users\UserName\AppData\Roaming\ | /Users/UserName/Library/Application Support | /home/UserName/ |
Applications | \Program Files\ or
\Program Files (x86)\ |
/Applications | Nil |
Bin | Nil | /bin | /bin/ |
Cookies | \Users\UserName\AppData\Local\Microsoft\Windows\INetCookies\ | /Users/UserName/Library/Cookies | Nil |
CurrentWorkingDirectory | Current working directory (depends on the location of the application). When run from Xojo, it is the path to Xojo. In a built app, it is the path to the built app. | Current working directory (depends on the location of the application). Usually "/". | Current working directory at the time the application was launched (uses getcwd). |
Desktop | \Users\UserName\Desktop\ | /Users/UserName/Desktop | /home/UserName/Desktop/ |
Documents | \Users\UserName\Documents\ | /Users/UserName/Documents | /home/UserName/Documents/ |
Etc | Nil | /private/etc | /etc/ |
Extensions | \Windows\System32\ | Nil | Nil |
Favorites | \Users\UserName\Favorites\ | /Users/UserName/Library/Favorites | Nil |
Fonts | \Windows\Fonts\ | /System/Library/Fonts | Nil |
GetFromDomainAndCode (domain as Integer, fourCharCode as String) | Raises PlatformNotSupportedException | Pass a class constant for the domain and a four-character code of a specific FolderItem The constants are: |
Raises PlatformNotSupportedException |
History | \Users\UserName\AppData\Local\Microsoft\Windows\History\ | /Users/UserName/Sites | Nil |
Home | Nil | /Users | /home/ |
InternetCache | \Users\UserName\AppData\Local\Microsoft\Windows\INetCache\ | /Users/UserName/Library/Caches | /home/UserName/.cache |
Library | Nil | /Library | /lib/ |
Mount | Nil | /Volumes | /mnt/ |
Movies | \Users\UserName\Videos\ | /Users/UserName/Movies | /home/UserName/Videos/ |
Music | \Users\UserName\Music\ | /Users/UserName/Music | /home/UserName/Music/ |
NetworkPlaces | \Users\UserName\AppData\Roaming\Microsoft\Windows\Network Shortcuts\ | Nil | Nil |
Pictures | \Users\UserName\Pictures\ | /Users/UserName/Pictures | /home/UserName/Pictures/ |
Preferences | \Users\UserName\AppData\Roaming\ | /Users/UserName/Library/Preferences On macOS, use SpecialFolder.ApplicationData to save your own files or directly call CFPreferences to save preferences files here. |
/home/UserName/ |
Printers | \Users\UserName\AppData\Roaming\Microsoft\Windows\Printer Shortcuts\ | /System/Library/Printers | Nil |
RecentItems | \Users\UserName\AppData\Roaming\Microsoft\Windows\Recent\ | /Users/UserName/Library/Recent Documents | Nil |
Resources
|
MyApp Folder\Resources | MyApp.app/Contents/Resources | MyApp Folder/Resources |
SBin | Nil | /sbin | /sbin/ |
SendTo | \Users\UserName\AppData\Roaming\Microsoft\Windows\SendTo\ | Nil | Nil |
SharedApplicationData | \ProgramData\ | /Library/Application Support | Nil |
SharedApplications | \Program Files\Common Files\ or
\Program Files (x86)\Common Files\ |
Nil | Nil |
SharedDesktop | \Users\Public\Desktop\ | Nil | Nil |
SharedDocuments | \Users\Public\Documents\ | /Users/Shared | Nil |
SharedFavorites | \Users\UserName\Favorites\ | Nil | Nil |
SharedPreferences | \ProgramData\ | /Library/Preferences | Nil |
SharedStartupItems | \ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\ | Nil | Nil |
SharedTemplates | \ProgramData\Microsoft\Windows\Templates\ | Nil | Nil |
StartupItems | \Users\UserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\ | Nil | Nil |
System | \Windows\System32\ | /System | Nil |
Templates | \Users\UserName\AppData\Roaming\Microsoft\Windows\Templates\ | Nil | Nil |
Temporary | \Users\UserName\AppData\Local\Temp\ | /private/var/folders/gp/.../T/TemporaryItems (varies) | /tmp/ |
Trash(relativeToVolume As FolderItem=Nil) | \Users\UserName\Desktop\Recycle Bin\ | /Users/UserName/.Trash | Nil |
UserBin | Nil | /usr/bin | /usr/bin/ |
UserHome | \Users\UserName\ | /Users/UserName | /home/UserName/ |
UserLibrary | Nil | /Users/UserName/Library | /usr/lib/ |
UserSBin | Nil | /usr/sbin | /usr/sbin/ |
Var
|
n/a | n/a | n/a |
Variable | Nil | /private/var | /var/ |
VarLog
|
n/a | n/a | n/a |
VariableLog | Nil | /private/var/log | /var/log/ |
Windows | \Windows\ | Nil | Nil |
Xojo Cloud
For Xojo Cloud, these are the only SpecialFolder methods that are usable. All others return Nil:
- Fonts
- SharedDocuments: The web server Shared_Documents folder.
- Documents: The Documents folder within the web app folder.
- Temporary: The web server tmp folder.
Notes
Not all types of folders are supported on all operating systems. After a call to SpecialFolder, check that the result not Nil. Please note that in a web app on a server, some folders do not exist. Like if your web app runs with Apache as CGI with the apache user, there will be no desktop folder.
On macOS, SpecialFolder.Temporary returns an item in the OS's TemporaryItems directory for the current user. The path contains a long system-defined string that cannot be specified. It looks similar to this:
:private:var:folders:pX:pXijpazEF5aGY39FGy9H7k+++TI:TemporaryItems:
On 64-bit versions of Windows, 32-bit applications created with Xojo will map SpecialFolder.Applications to "Program Files (x86)" instead of "Program Files".
Sample Code
The following code gets a FolderItem for the Application Data folder and displays its native path.
f = SpecialFolder.ApplicationData
If f <> Nil Then
MessageBox(f.NativePath)
Else
MessageBox("There is no Application Data folder on this computer.")
End If
The following example returns a FolderItem for the Documents directory on Windows and Mac OS X and the Home directory on Linux.
If Not TargetLinux Then
f = SpecialFolder.Documents
Else
f = SpecialFolder.Home
End If
If f <> Nil Then
// proceed normally
Else
MessageBox("FolderItem does not exist!")
End If
See Also
FolderItem class.