mac上有个非常好用的命令 open, 无论输入的是相对路径还是绝对路径,都可以智能的打开资源管理器(Finder)。 如果是系统注册的后缀的文件, 也可以使用对应的软件打开对应的文件。
windows 有个命令explorer 也可以打开资源管理器, 但对相对路径支持的不好, 也不可以使用对应软件打开相应后缀的文件。但对于熟练使用mac上的强迫症来说是不可以接受的,所以这里写了一个c# 程序, 把编译出来的exe 重命名为open.exe, 放在c:/windows 目录下, 就可以实现类似mac上open命令的效果了。
static class Program
{
static void Main(string[] args)
{
string str = Process.GetCurrentProcess().MainModule.FileName;
FileInfo file = new FileInfo(str);
var dir = file.DirectoryName;
if (args != null && args.Length > 0)
{
if (Directory.Exists(args[0])) // global
{
DirectoryInfo dinfo = new DirectoryInfo(args[0]);
Process.Start(dinfo.FullName);
}
if(File.Exists(args[0]))
{
FileInfo finfo = new FileInfo(args[0]);
OpenSpecFile(finfo.FullName);
}
}
else
{
Process.Start(dir);
}
}
static void OpenSpecFile(string file)
{
Process MyProcess = new Process();
MyProcess.StartInfo.FileName = file;
MyProcess.StartInfo.Verb = "Open";
MyProcess.StartInfo.CreateNoWindow = true;
MyProcess.Start();
}
}
这篇博客介绍了如何通过编写C#程序,在Windows系统中实现类似Mac上的'open'命令功能。这个程序能够智能识别路径并打开资源管理器,对于相对路径和文件类型处理更加友好,使得Windows用户也能享受到类似于Mac的便捷操作体验。
3286

被折叠的 条评论
为什么被折叠?



