相关疑难解决方法(0)

检查Windows路径中是否存在可执行文件

如果我使用ShellExecute(或在.net中System.Diagnostics.Process.Start())运行进程,则启动文件名进程不需要是完整路径.

如果我想开始记事本,我可以使用

Process.Start("notepad.exe");
Run Code Online (Sandbox Code Playgroud)

代替

Process.Start(@"c:\windows\system32\notepad.exe");
Run Code Online (Sandbox Code Playgroud)

因为direcotry c:\windows\system32是PATH环境变量的一部分.

如何在不执行进程且不解析PATH变量的情况下检查PATH上是否存在文件?

System.IO.File.Exists("notepad.exe"); // returns false
(new System.IO.FileInfo("notepad.exe")).Exists; // returns false
Run Code Online (Sandbox Code Playgroud)

但我需要这样的东西:

System.IO.File.ExistsOnPath("notepad.exe"); // should return true
Run Code Online (Sandbox Code Playgroud)

System.IO.File.GetFullPath("notepad.exe"); // (like unix which cmd) should return
                                           // c:\windows\system32\notepad.exe
Run Code Online (Sandbox Code Playgroud)

是否有预定义的类可以在BCL中执行此任务?

.net c# file

56
推荐指数
5
解决办法
3万
查看次数

测试PowerShell中的可执行文件是否在路径中

在我的脚本中,我即将运行一个命令

pandoc -Ss readme.txt -o readme.html
Run Code Online (Sandbox Code Playgroud)

但我不确定是否pandoc已安装.所以我想做(伪代码)

if (pandoc in the path)
{
    pandoc -Ss readme.txt -o readme.html
}
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做呢?

powershell

54
推荐指数
2
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

file ×1

powershell ×1