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();
}
}