Files
wcs/货架标准上位机/Tool/Folder.cs
2024-10-17 12:59:41 +08:00

74 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS管理系统
{
/// <summary>
/// 文件夹操作
/// </summary>
public static class Folder
{
/// <summary>
/// 打开目录
/// </summary>
/// <param name="folderPath">目录路径比如C:\Users\Administrator\</param>
public static void OpenFolder(string folderPath)
{
if (string.IsNullOrEmpty(folderPath))
return;
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
psi.Arguments = folderPath;
process.StartInfo = psi;
try
{
process.Start();
}
catch (Exception ex)
{
throw ex;
}
finally
{
process?.Close();
}
}
/// <summary>
/// 打开目录且选中文件
/// </summary>
/// <param name="filePathAndName">文件的路径和名称比如C:\Users\Administrator\test.txt</param>
public static void OpenFolderAndSelectedFile(string filePathAndName)
{
if (string.IsNullOrEmpty(filePathAndName))
return;
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
psi.Arguments = "/e,/select," + filePathAndName;
process.StartInfo = psi;
//process.StartInfo.UseShellExecute = true;
try
{
process.Start();
}
catch (Exception ex)
{
throw ex;
}
finally
{
process?.Close();
}
}
}
}