Common/Gardener.Common/FileHelper.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System.IO;
namespace Gardener.Common;
public class FileHelper
{
public static void CreateFileReplace(string fileFullPath, string contentStr)
{
string? directoryPath = GetDirectory(fileFullPath);
if (directoryPath == null) { return; }
CreateDirectory(directoryPath);
File.WriteAllText(fileFullPath, contentStr, System.Text.Encoding.UTF8);
}
/// <summary>
/// Get full directory of a file
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string? GetDirectory(string filePath)
{
FileInfo file = new FileInfo(filePath);
DirectoryInfo? directory = file.Directory;
return directory?.FullName;
}
public static void CreateDirectory(string directoryPath)
{
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
}
/// <summary>
///
/// </summary>
/// <param name="path">File or folder path</param>
/// <param name="openParent"></param>
public static void OpenFolder(string path, bool openParent = false)
{
try
{
// File
if (File.Exists(path))
{
var pPath= new DirectoryInfo(path).Parent?.FullName;
if(pPath!=null)
{
System.Diagnostics.Process.Start("explorer.exe", pPath);
}
}
// Folder
else if (Directory.Exists(path))
{
var dir = new DirectoryInfo(path);
var openDir = dir.FullName;
if (openParent)
{
后面还有 36 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
