Environment.GetFolderPath 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得由指定列舉識別的系統特殊資料夾路徑。
多載
| 名稱 | Description |
|---|---|
| GetFolderPath(Environment+SpecialFolder) |
取得指定的系統特殊資料夾路徑。 |
| GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) |
透過指定的存取選項取得指定系統特殊資料夾的路徑。 |
GetFolderPath(Environment+SpecialFolder)
取得指定的系統特殊資料夾路徑。
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
其中一個列舉值用來識別系統特殊資料夾。
傳回
如果該系統特殊資料夾實體存在於你的電腦上,則是該路徑;否則,則為空字串(“”)。
若該資料夾未由作業系統建立、現有資料夾已被刪除,或該資料夾是虛擬目錄(如 My Computer),且不對應實體路徑,該資料夾將不存在。
例外狀況
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)
透過指定的存取選項取得指定系統特殊資料夾的路徑。
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
其中一個列舉值用來識別系統特殊資料夾。
列舉值之一,指定存取特殊資料夾的選項。
傳回
如果該系統特殊資料夾實體存在於你的電腦上,則是該路徑;否則,則為空字串(“”)。
若該資料夾未由作業系統建立、現有資料夾已被刪除,或該資料夾是虛擬目錄(如 My Computer),且不對應實體路徑,該資料夾將不存在。
例外狀況
目前的平台不支援。
備註
此方法可取得系統特殊資料夾的路徑,如 Program Files、Programs、System 或 Startup,可用來存取常見資訊。 特殊資料夾由系統預設設定,或使用者在安裝 Windows 版本時明確設定。
參數 folder 指定要檢索的特殊資料夾,必須是列舉中的值 Environment.SpecialFolder 之一;任何其他值都會拋出例外。
欲了解更多特殊資料夾資訊,請參閱恆定特殊項目 ID 清單(CSIDL)。