using System;
using System.Diagnostics;
class Program
{
static void Main()
{
// 定义要打开的文件夹路径
string folderPath = @"C:\ExampleFolder";
// 检查文件夹路径是否为空或无效
if (string.IsNullOrEmpty(folderPath))
{
Console.WriteLine("文件夹路径不能为空或无效");
return;
}
// 使用Process.Start方法打开文件夹
try
{
Process.Start(new ProcessStartInfo(folderPath) { UseShellExecute = true });
}
catch (Exception ex)
{
Console.WriteLine($"打开文件夹时发生错误: {ex.Message}");
}
}
}
System和System.Diagnostics命名空间,其中System.Diagnostics提供了与系统进程交互的功能。Main方法是程序的入口点。folderPath变量存储要打开的文件夹路径。请根据实际情况修改此路径。string.IsNullOrEmpty方法检查路径是否为空或无效。Process.Start方法并传递ProcessStartInfo对象来打开指定的文件夹。UseShellExecute = true确保使用操作系统外壳程序执行操作。try-catch块捕获并处理可能发生的异常,例如路径无效或无法访问文件夹的情况。上一篇:c# 链表
下一篇:c# string format
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站