Environment.GetFolderPath 方法

定义

获取由指定枚举标识的系统特殊文件夹的路径。

重载

名称 说明
GetFolderPath(Environment+SpecialFolder)

获取指定系统特殊文件夹的路径。

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

使用用于访问特殊文件夹的指定选项获取指定系统特殊文件夹的路径。

GetFolderPath(Environment+SpecialFolder)

Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs

获取指定系统特殊文件夹的路径。

public:
 static System::String ^ GetFolderPath(Environment::SpecialFolder folder);
public static string GetFolderPath(Environment.SpecialFolder folder);
static member GetFolderPath : Environment.SpecialFolder -> string
Public Shared Function GetFolderPath (folder As Environment.SpecialFolder) As String

参数

folder
Environment.SpecialFolder

标识系统特殊文件夹的枚举值之一。

返回

指定系统特殊文件夹的路径(如果计算机上存在该文件夹);否则为空字符串(“)。

如果操作系统未创建该文件夹、删除现有文件夹或文件夹是虚拟目录(如“我的计算机”),则文件夹将不存在于物理路径。

例外

folder 不是 . 的成员 Environment.SpecialFolder

当前平台不受支持。

示例

以下示例演示如何使用 GetFolderPath 该方法返回和显示与 folder 参数关联的路径。

// Sample for the Environment.GetFolderPath method
using System;

class Sample
{
    public static void Main()
    {
    Console.WriteLine();
    Console.WriteLine("GetFolderPath: {0}",
                 Environment.GetFolderPath(Environment.SpecialFolder.System));
    }
}
/*
This example produces the following results:

GetFolderPath: C:\WINNT\System32
*/
// Sample for the Environment.GetFolderPath method
open System

printfn $"\nGetFolderPath: {Environment.GetFolderPath Environment.SpecialFolder.System}"
            
// This example produces the following results:
//     GetFolderPath: C:\WINNT\System32
' Sample for the Environment.GetFolderPath method
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
   End Sub
End Class
'
'This example produces the following results:
'
'GetFolderPath: C:\WINNT\System32
'

注解

此方法检索系统特殊文件夹的路径,例如 Program Files、Programs、System 或 Startup,可用于访问通用信息。 安装Windows版本时,系统默认或用户显式设置特殊文件夹。

folder 参数指定要检索的特殊文件夹,并且必须是枚举中的 Environment.SpecialFolder 值之一;任何其他值都引发异常。

有关特殊文件夹的详细信息,请参阅常量特殊项 ID 列表(CSIDL)。

另请参阅

适用于

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs

使用用于访问特殊文件夹的指定选项获取指定系统特殊文件夹的路径。

public:
 static System::String ^ GetFolderPath(Environment::SpecialFolder folder, Environment::SpecialFolderOption option);
public static string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option);
static member GetFolderPath : Environment.SpecialFolder * Environment.SpecialFolderOption -> string
Public Shared Function GetFolderPath (folder As Environment.SpecialFolder, option As Environment.SpecialFolderOption) As String

参数

folder
Environment.SpecialFolder

标识系统特殊文件夹的枚举值之一。

option
Environment.SpecialFolderOption

枚举值之一,指定用于访问特殊文件夹的选项。

返回

指定系统特殊文件夹的路径(如果计算机上存在该文件夹);否则为空字符串(“)。

如果操作系统未创建该文件夹、删除现有文件夹或文件夹是虚拟目录(如“我的计算机”),则文件夹将不存在于物理路径。

例外

folder 不是 . 的成员 Environment.SpecialFolder

-或-

option 不是 . 的成员 Environment.SpecialFolderOption

当前平台不受支持。

注解

此方法检索系统特殊文件夹的路径,例如 Program Files、Programs、System 或 Startup,可用于访问通用信息。 安装Windows版本时,系统默认或用户显式设置特殊文件夹。

folder 参数指定要检索的特殊文件夹,并且必须是枚举中的 Environment.SpecialFolder 值之一;任何其他值都引发异常。

有关特殊文件夹的详细信息,请参阅常量特殊项 ID 列表(CSIDL)。

另请参阅

适用于