Files
wcs/货架标准上位机/Tool/Folder.cs
hehaibing-1996 ee7ee7a672 批量导入
2025-01-20 17:45:05 +08:00

80 lines
2.1 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.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <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();
}
}
public static void CopyFile(string sourcePath, string destinationPath)
{
File.Copy(sourcePath, destinationPath, true); // true 表示如果目标文件存在则覆盖它
}
}
}