Environment.GetFolderPath 方法

定義

取得由指定之列舉識別的系統特殊資料夾的路徑。

多載

GetFolderPath(Environment+SpecialFolder)

取得指定之系統特殊資料夾的路徑。

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

使用指定選項存取特殊資料夾,取得指定系統特殊資料夾的路徑。

GetFolderPath(Environment+SpecialFolder)

來源:
Environment.cs
來源:
Environment.cs
來源:
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 (常數特殊專案識別碼清單)

另請參閱

適用於

GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)

來源:
Environment.cs
來源:
Environment.cs
來源:
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 (常數特殊專案識別碼清單)

另請參閱

適用於