Get Environment Folder
UiPath.Core.Activities.GetEnvironmentFolder
Use this activity to retrieve the path to system special folders (such as Desktop, Documents, AppData, etc.) using .NET's Environment.SpecialFolder enumeration. Understanding the platform-specific behavior is essential for building reliable cross-platform automation workflows.
The SpecialFolder enumeration is consistent across platforms, but the actual folder mappings and availability differ significantly between Windows and cross-platform environments. Many Windows-specific folders return an empty string on Linux/macOS.
Properties
Common
- DisplayName - The display name of the activity.
Input
- SpecialFolder - The SpecialFolder whose path is to be retrieved. Select from the available
Environment.SpecialFolderenumeration values.
Output
- FolderPath - The full folder path of the selected SpecialFolder. Returns an empty string if the folder is not available on the current platform.
Misc
- Private - If selected, the values of variables and arguments are no longer logged at Verbose level.
Platform-specific behavior
Windows environment
When running on Windows:
- All standard special folders resolve to their expected Windows paths (e.g.,
Desktop,ProgramFiles,System,ApplicationData). - Windows-only folders such as
ProgramFiles,ProgramFilesX86,Windows,AdminTools, andCommonProgramFilesreturn valid paths. - Folders typically resolve to locations under
C:\Users\<username>or system directories likeC:\Windows.
Cross-platform environment
When running on Linux or macOS:
- Only a subset of special folders resolve to valid paths; many Windows-specific folders return an empty string.
- Folder paths follow XDG Base Directory specifications on Linux (using environment variables like
$XDG_CONFIG_HOME,$XDG_DATA_HOME) and macOS conventions. - The activity never creates directories; it only resolves known locations based on the operating system.
- If a folder cannot be resolved on the current platform, the activity returns an empty string (not null) and does not throw an exception.
Common folder mappings
Cross-platform folders
These folders typically resolve on both Windows and cross-platform environments:
- UserProfile - Windows:
C:\Users\<user>, Linux/macOS:$HOME - Desktop - Windows:
C:\Users\<user>\Desktop, Linux/macOS:~/Desktop(if present) - MyDocuments - Windows:
C:\Users\<user>\Documents, Linux/macOS:~/Documents(if present) - ApplicationData - Windows:
%APPDATA%(Roaming), Linux/macOS:~/.config(XDG) - LocalApplicationData - Windows:
%LOCALAPPDATA%, Linux/macOS:~/.local/share(XDG)
Windows-only folders
These folders return valid paths on Windows but typically return an empty string on Linux/macOS:
- ProgramFiles, ProgramFilesX86 - Windows program installation directories
- System, SystemX86, Windows - Windows system directories
- CommonApplicationData - Windows:
%PROGRAMDATA%, Linux/macOS: empty string - CommonProgramFiles, CommonProgramFilesX86 - Shared program files
- AdminTools, Templates, Favorites, Recent, SendTo, StartMenu, Startup - Windows shell folders
Platform-specific considerations
- Fonts - Windows:
%WINDIR%\Fonts, macOS:/System/Library/Fonts(system) or/Library/Fonts(user), Linux: varies by distribution, often returns empty string - Desktop, MyDocuments - May return empty string if the directory doesn't exist in the user profile, even on platforms where they are expected
Best practices
- Always validate the result: Check for
string.IsNullOrEmpty(folderPath)before using the returned path, as many folders may not exist on certain platforms. - For cross-platform workflows: Prefer using
UserProfile,ApplicationData, orLocalApplicationDatafor storing application data, as these have consistent mappings across platforms. - Avoid Windows-only folders: Don't rely on folders like
ProgramFiles,System, orWindowsin cross-platform workflows, as they will return empty strings on Linux/macOS. - Handle missing directories: The activity does not create directories. If you need to write to a special folder, verify it exists and create it if necessary.
- Test on target platforms: Folder availability can vary based on user profile configuration, especially for presence-sensitive folders like Desktop and Documents.
- Containerized environments: Be aware that containerized or restricted environments may return empty strings for more folders due to missing or inaccessible paths.
Return value
- Returns the full folder path as a string if the special folder is available on the current platform.
- Returns an empty string (
string.Empty) if the folder cannot be resolved on the current platform. - Never returns null and does not throw exceptions for unsupported folders.
Example scenarios
Scenario 1: Retrieving UserProfile
- Windows: Returns
C:\Users\<username> - Linux/macOS: Returns
/home/<username>or/Users/<username>
Scenario 2: Retrieving ProgramFiles
- Windows: Returns
C:\Program Files - Linux/macOS: Returns empty string
Scenario 3: Retrieving ApplicationData
- Windows: Returns
C:\Users\<username>\AppData\Roaming - Linux/macOS: Returns
~/.config(XDG specification)
Scenario 4: Retrieving Desktop when folder doesn't exist
- All Platforms: Returns empty string if the Desktop folder is not present in the user profile