Environment.GetFolderPath 方法

定义

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

重载

GetFolderPath(Environment+SpecialFolder)

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

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

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

GetFolderPath(Environment+SpecialFolder)

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 namespace System;
int 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
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 值之一;任何其他值都会引发异常。

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

另请参阅

适用于

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

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 的成员。

- 或 -

options 不是 Environment.SpecialFolderOption 的成员。

不支持当前平台。

注解

此方法检索系统特殊文件夹(例如 Program Files、Programs、System 或 Startup)的路径,这些文件夹可用于访问常见信息。 默认情况下,特殊文件夹由系统设置,或在安装 Windows 版本时由用户显式设置。

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

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

另请参阅

适用于