资源管理器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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值