activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

工作流活动

上次更新日期 2026年3月6日

获取环境文件夹

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.

属性

常见
  • “显示名称”- 活动的显示名称。
输入
  • SpecialFolder - The SpecialFolder whose path is to be retrieved. Select from the available Environment.SpecialFolder enumeration values.
输出
  • FolderPath - The full folder path of the selected SpecialFolder. Returns an empty string if the folder is not available on the current platform.
其他
  • “私有”- 选中后将不再以“Verbose”级别记录变量和参数的值。

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, and CommonProgramFiles return valid paths.
  • Folders typically resolve to locations under C:\Users\<username> or system directories like C:\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

最佳实践

  • 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, or LocalApplicationData for storing application data, as these have consistent mappings across platforms.
  • Avoid Windows-only folders: Don't rely on folders like ProgramFiles, System, or Windows in 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.

返回值

  • 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.

示例场景

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

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新