網站首頁 編程語言 正文
一、實現內容
1.1實現的功能
想要實現:
①打開指定的目錄;
②打開指定的目錄且選中指定文件;
③打開指定文件
1.2實現的效果
二、實現操作
/// <summary>
/// 打開目錄
/// </summary>
/// <param name="folderPath">目錄路徑(比如:C:\Users\Administrator\)</param>
private static void OpenFolder(string folderPath)
{
if (string.IsNullOrEmpty(folderPath)) return;
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
psi.Arguments = folderPath;
process.StartInfo = psi;
try
{
process.Start();
}
catch (Exception ex)
{
throw ex;
}
finally
{
process?.Close();
}
}
/// <summary>
/// 打開目錄且選中文件
/// </summary>
/// <param name="filePathAndName">文件的路徑和名稱(比如:C:\Users\Administrator\test.txt)</param>
private static void OpenFolderAndSelectedFile(string filePathAndName)
{
if (string.IsNullOrEmpty(filePathAndName)) return;
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
psi.Arguments = "/e,/select,"+filePathAndName;
process.StartInfo = psi;
//process.StartInfo.UseShellExecute = true;
try
{
process.Start();
}
catch (Exception ex)
{
throw ex;
}
finally
{
process?.Close();
}
}
/// <summary>
/// 打開文件
/// </summary>
/// <param name="filePathAndName">文件的路徑和名稱(比如:C:\Users\Administrator\test.txt)</param>
/// <param name="isWaitFileClose">是否等待文件關閉(true:表示等待)</param>
private static void OpenFile(string filePathAndName,bool isWaitFileClose=true)
{
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo(filePathAndName);
process.StartInfo = psi;
process.StartInfo.UseShellExecute = true;
try
{
process.Start();
//等待打開的程序關閉
if (isWaitFileClose)
{
process.WaitForExit();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
process?.Close();
}
}
三、Windows 資源管理器參數說明
Windows資源管理器參數的說明
序號 | 參數命令 | 說明 |
1 | Explorer /n | 此命令使用默認設置打開一個資源管理器窗口。顯示的內容通常是安裝 Windows 的驅動器的根目錄 |
2 | Explorer /e | 此命令使用默認視圖啟動 Windows 資源管理器 |
3 | Explorer /e,C:\Windows | 此命令使用默認視圖啟動 Windows 資源管理器,并把焦點定位在 C:\Windows路徑上 |
4 | Explorer /root, C:\Windows\Cursors | 此命令啟動 Windows 資源管理器后焦點定位在 C:\Windows\Cursors folder路徑上。此示例使用 C:\Windows\Cursors 作為 Windows 資源管理器的“根”目錄 |
5 | Explorer /select, C:\Windows\Cursors\banana.ani | 此命令啟動 Windows 資源管理器后選定“C:\Windows\Cursors\banana.ani”文件。 |
6 | Explorer /root, \\server\share, select, Program.exe | 此命令啟動 Windows 資源管理器時以遠程共享作為“根”文件夾,而且 Program.exe 文件將被選中 |
原文鏈接:https://coffeemilk.blog.csdn.net/article/details/123472064
相關推薦
- 2023-09-18 element-plus 字體變色之cell-style
- 2022-01-08 解決npm install報錯問題--npm install xxx npm ERR! code E
- 2022-06-13 ASP.NET?Core配置文件的獲取和設置_實用技巧
- 2022-06-22 android實現注冊登錄程序_Android
- 2022-07-07 Asp.Net上傳文件并配置可上傳大文件的方法_基礎應用
- 2022-06-10 C語言?模擬實現strlen函數詳解_C 語言
- 2022-09-28 使用C語言實現三子棋小游戲_C 語言
- 2022-06-13 Flutter實現自定義搜索框AppBar的示例代碼_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支