zoukankan      html  css  js  c++  java
  • Process打开文件

    引用:using System.Diagnostics;

    打开文件夹:

    System.Diagnostics.Process.Start(FilePath);

    打开文件夹中某个文件:

    System.Diagnostics.Process.Start(FilePath+"/"+FileName);

    打开文件夹并选中单个文件:

    通用的是这个方案:

    System.Diagnostics.Process.Start("Explorer", "/select,"+ FilePath+""+FileName);

    System.Diagnostics.Process.Start("Explorer.exe", "/select,"+ FilePath+""+FileName);

    但是如果文件包含特殊字符就会出现问题,比如文件名包含逗号时,就打开的位置错误,打开到了 我的文档 文件夹。

    正确的解决方案是将需要选中的文件用双引号括起来,如下:

    var argment = string.Format(@"/select,""{0}""", filePath);


    System.Diagnostics.Process.Start("Explorer", argment);

    或者

    System.Diagnostics.Process.Start("Explorer.exe", argment);

    注:(explorer,explorer.exe,select,不区分大小写,"/selecet,"其中"/,"都不能少,FilePath为文件路径不包含文件名)

  • 相关阅读:
    GolandQuick编辑器快捷键
    GitStand
    高阶函数
    文本和字节序列
    元组用法
    映射的弹性键查询
    字典的setdefault()
    数组、内存视图、双向队列
    Python之random.seed()用法
    用bisect来管理已排序的序列
  • 原文地址:https://www.cnblogs.com/sczmzx/p/4617999.html
Copyright © 2011-2022 走看看