資源管理器C:\Windows\explorer.exe命令行參數及在c# aps.net core中的調用(打開文件夾)

語法

EXPLORER.EXE [/n][/e][,/root,<object>][[,/select],<sub object>]

/n: 默認選項,用我的電腦視圖爲每個選中的item打開一個單獨的窗口,  即使該窗口已經被打開。

/e: 使用資源管理器視圖。資源管理器視圖和Windows 3.x的文件管理器非常相似。

/root,<object>: 指定視圖目錄根,默認使用桌面作爲根目錄。

/select,<sub object>: 選中指定對象。如果使用"/select" , 則父目錄被打開,並選中指定對象。

例子

一般用法

explorer C:\Windows

打開資源管理器視圖並以C:\Windows爲目錄根瀏覽

explorer /e,/root,C:\Windows

打開資源管理器視圖並選中Calc.exe

explorer /e,/select,c:\windows\system32\calc.exe

注意

/root和/select最好不要同時使用

文件夾參數必須使用反斜槓-\

文件夾參數如果包含空格請用""包裹

在c# aps.net core中的調用

        /// <summary>
        /// 打開文件夾
        /// </summary>
        public static void Open(string path)
        {
            System.Diagnostics.Process.Start(@"C:\Windows\explorer.exe", path.ReplaceSprit(false).AddQuotation());
        }

        /// <summary>
        /// 打開文件夾並選中文件
        /// </summary>
        public static void OpenFileFloder(string path)
        {
            System.Diagnostics.Process.Start(@"C:\Windows\explorer.exe", "/select," + path.ReplaceSprit(false).AddQuotation());
        }

//替換斜槓及包裹""代碼:

        /// <summary>
        /// 替換斜槓
        /// </summary>
        public static string ReplaceSprit(this string text, bool positive = true)
        {
            if (positive)
                return text.Replace('\\', '/');
            return text.Replace('/', '\\');
        }

        /// <summary>
        /// 添加雙引號
        /// </summary>
        public static string AddQuotation(this string text)
        {
            if (text.StartWith('"'))
                return text;
            return string.Format("\"{0}\"", text);
        }

參考 https://www.cnblogs.com/ymind/archive/2012/03/30/explorer-command-args.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章