Environment.GetFolderPath Environment.GetFolderPath Environment.GetFolderPath Environment.GetFolderPath Method

定义

获取由指定枚举标识的系统特殊文件夹的路径。Gets the path to the system special folder that is identified by the specified enumeration.

重载

GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder)

获取由指定枚举标识的系统特殊文件夹的路径。Gets the path to the system special folder that is identified by the specified enumeration.

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

获取由指定枚举标识的系统特殊文件夹的路径,并使用用于访问特殊文件夹的指定选项。Gets the path to the system special folder that is identified by the specified enumeration, and uses a specified option for accessing special folders.

GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder) GetFolderPath(Environment+SpecialFolder)

获取由指定枚举标识的系统特殊文件夹的路径。Gets the path to the system special folder that is identified by the specified enumeration.

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 Environment.SpecialFolder Environment.SpecialFolder Environment.SpecialFolder

标识系统特殊文件夹的枚举值之一。One of enumeration values that identifies a system special folder.

返回

如果指定的系统特殊文件夹实际存在于您的计算机上,则为到该文件夹的路径;否则为空字符串 ("")。The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string ("").

如果系统未创建文件夹、已删除现有文件夹,或者文件夹是不对应物理路径的虚拟目录(例如"我的电脑"),则该文件夹不会实际存在。A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path.

异常

示例

下面的示例演示如何使用GetFolderPath方法返回并显示folder与参数关联的路径。The following example demonstrates how to use the GetFolderPath method to return and display the path associated with the folder parameter.

// 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
Imports System

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

注解

此方法检索系统特殊文件夹的路径, 例如, 可用于访问常见信息的程序文件、程序、系统或启动。This method retrieves the path to a system special folder, such as Program Files, Programs, System, or Startup, which can be used to access common information. 默认情况下, 特殊文件夹由系统设置, 或在安装 Windows 版本时由用户显式设置。Special folders are set by default by the system, or explicitly by the user, when installing a version of Windows.

参数指定要检索的特殊文件夹, 并且必须是Environment.SpecialFolder枚举中的值之一; 其他任何值都会引发异常。 folderThe folder parameter designates the special folder to retrieve and must be one of the values in the Environment.SpecialFolder enumeration; any other value throws an exception.

有关特殊文件夹的详细信息, 请参阅CSIDL值主题。For more information about special folders, see the CSIDL values topic.

安全性

FileIOPermission
用于访问路径本身的信息。for access to the information in the path itself. 关联的枚举:PathDiscoveryAssociated enumeration: PathDiscovery

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

获取由指定枚举标识的系统特殊文件夹的路径,并使用用于访问特殊文件夹的指定选项。Gets the path to the system special folder that is identified by the specified enumeration, and uses a specified option for accessing special folders.

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 Environment.SpecialFolder Environment.SpecialFolder Environment.SpecialFolder

标识系统特殊文件夹的枚举值之一。One of the enumeration values that identifies a system special folder.

option
Environment.SpecialFolderOption Environment.SpecialFolderOption Environment.SpecialFolderOption Environment.SpecialFolderOption

指定用于访问特殊文件夹的选项的枚举值之一。One of the enumeration values that specifies options to use for accessing a special folder.

返回

如果指定的系统特殊文件夹实际存在于您的计算机上,则为到该文件夹的路径;否则为空字符串 ("")。The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string ("").

如果系统未创建文件夹、已删除现有文件夹,或者文件夹是不对应物理路径的虚拟目录(例如"我的电脑"),则该文件夹不会实际存在。A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path.

异常

folder 不是 Environment.SpecialFolder 的成员。folder is not a member of Environment.SpecialFolder. -or-

options 不是 Environment.SpecialFolderOption 的成员。options is not a member of Environment.SpecialFolderOption.

注解

此方法检索系统特殊文件夹的路径, 例如, 可用于访问常见信息的程序文件、程序、系统或启动。This method retrieves the path to a system special folder, such as Program Files, Programs, System, or Startup, which can be used to access common information. 默认情况下, 特殊文件夹由系统设置, 或在安装 Windows 版本时由用户显式设置。Special folders are set by default by the system, or explicitly by the user, when installing a version of Windows.

参数指定要检索的特殊文件夹, 并且必须是Environment.SpecialFolder枚举中的值之一; 其他任何值都会引发异常。 folderThe folder parameter designates the special folder to retrieve and must be one of the values in the Environment.SpecialFolder enumeration; any other value throws an exception.

有关特殊文件夹的详细信息, 请参阅CSIDL值主题。For more information about special folders, see the CSIDL values topic.

安全性

FileIOPermission
用于访问路径本身的信息。for access to the information in the path itself. 关联的枚举:PathDiscoveryAssociated enumeration: PathDiscovery

适用于