.NET C#中使用Windows Explorer或者MacOS Finder打开指定文件夹

       只需要使用Process.Start启动外部进程打开指定路径即可。比如:

        private async void OnOpenAppDirectory(object sender, RoutedEventArgs e)
        {
            var directory = AppFramework.GetRuntimeApplicationDirectory();

            try
            {
                if (OperatingSystem.IsWindows())
                {
                    Process.Start("explorer.exe", $"\"{directory}\"");
                }
                else if (OperatingSystem.IsMacOS())
                {
                    Process.Start("open", $"\"{directory}\"");
                }
            }
            catch(Exception ex)
            {
                await MessageBoxUtils.ShowWarningAsync(this, "Warning", ex.Message);
            }
        }

      Windows下启动explorer.exe,MacOS下启动open 即可。

posted @ 2023-03-22 21:19  bodong  阅读(167)  评论(0编辑  收藏  举报