DiLu.Expansion.File 1.1.0

dotnet add package DiLu.Expansion.File --version 1.1.0
                    
NuGet\Install-Package DiLu.Expansion.File -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DiLu.Expansion.File" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DiLu.Expansion.File" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="DiLu.Expansion.File" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DiLu.Expansion.File --version 1.1.0
                    
#r "nuget: DiLu.Expansion.File, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DiLu.Expansion.File@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DiLu.Expansion.File&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=DiLu.Expansion.File&version=1.1.0
                    
Install as a Cake Tool

的卢文件扩展组件

介绍

的卢文件操作扩展,支持磁盘、FTP、minio

使用说明

本地磁盘 (LocalDisk)

//获取文件流
var fileStream = await SourceFile.BuildGetLocalDiskFileConfig(SourceRootFolder, null).GetAsync();
var fileStream = await Path.Combine(SourceRootFolder, "", SourceFile).BuildGetLocalDiskFileConfig().GetAsync();

//保存文件后获取保存的相对路径
var fileRelativePath = await fileStream
    .BuildSaveFileStreamToLocalDiskConfig(TargetFolder, FileGroupName, Path.GetExtension(SourceFile))
    .SaveAsync();
Console.WriteLine($"保存的相对路径是:{fileRelativePath}");

//删除文件
await fileRelativePath.BuildDeleteLocalDiskFileConfig(TargetFolder, FileGroupName).DeleteAsync();
await fileFullPath.BuildDeleteLocalDiskFileConfig().DeleteAsync();
//删除文件夹
await directoryFullPath.BuildDeleteLocalDiskFolderConfig().DeleteAsync();
await rootDirectory.BuildDeleteLocalDiskFolderConfig(FileGroupName, "2025/03/28").DeleteAsync();

//查询文件列表
await foreach (var fileInfo in rootDirectory.BuildSearchLocalDiskFileConfig(FileGroupName, null,
                   SearchOption.AllDirectories).SearchAsync())
{
    Console.WriteLine($"{fileInfo.FileName}-----{fileInfo.Extension}---{fileInfo.DirectoryName}");
    await Task.Delay(0);
}

await foreach (var fileInfo in fileFullPath.BuildSearchLocalDiskFileConfig().SearchAsync())
{
    Console.WriteLine($"{fileInfo.FileName}-----{fileInfo.Extension}---{fileInfo.DirectoryName}");
    await Task.Delay(0);
}

FTP服务器 (FTP)

//创建客户端
var ftpClient = new AsyncFtpClient(FtpHost, FtpUser, FtpPassword, FtpPort);
//获取文件流
var fileStream2 = await "2025/04/09/2025040920151015849.jpg"
    .BuildGetFtpFileConfig("/", "Test", ftpClient, false).GetAsync();
await using (fileStream2)
{
    Console.WriteLine($"文件大小 {fileStream2?.Length ?? 0}");
}

await ftpClient.CloseFtpClientConnectAsync();

//保存文件后获取保存的相对路径
var fileStream = await SourceFile.BuildGetLocalDiskFileConfig(SourceRootFolder, null).GetAsync();
await using (fileStream)
{
    await fileStream
        .BuildSaveFileStreamToFtpConfig("/", "Images", Path.GetExtension(SourceFile), ftpClient, false)
        .SaveAsync();
}

await ftpClient.CloseFtpClientConnectAsync();

//删除文件
await "2025/04/10/2025041021432585288.jpg"
    .BuildDeleteFtpFileConfig("/", "Images", ftpClient, false)
    .DeleteAsync();
await ftpClient.CloseFtpClientConnectAsync();
//删除文件夹
await "/Images/".BuildDeleteFtpFolderConfig(ftpClient, false).DeleteAsync();
await ftpClient.CloseFtpClientConnectAsync();

//查询文件列表
await foreach (var fileInfo in "/".BuildSearchFtpFileConfig(ftpClient, false).SearchAsync())
{
    Console.WriteLine($"{fileInfo.FileName}-----{fileInfo.Extension}---{fileInfo.DirectoryFullPath}");
    await Task.Delay(0);
}
await ftpClient.CloseFtpClientConnectAsync();

Minio (Minio)

//创建客户端
var minio = new MinioClient()
    .WithEndpoint(MinioIp, MinioPort)
    .WithCredentials(MinioAccessKey, MinioSecretKey)
    .Build();
//获取文件流
var fileStream1 = await "2025/04/12/2025041221122784472.jpg"
    .BuildGetMinioFileConfig("/", "照片", minio, MinioBucketName).GetAsync();

//保存文件后获取保存的相对路径
await fileStream
    .BuildSaveFileStreamToMinioConfig("/", "照片2", Path.GetExtension(SourceFile), minio, MinioBucketName)
    .SaveAsync();

//删除文件
await "2025/04/12/2025041221122784472.jpg"
    .BuildDeleteMinioFileConfig("/", "照片", minio, MinioBucketName)
    .DeleteAsync();

//查询文件列表
await foreach (var fileInfo in "/"
                   .BuildSearchMinioFileConfig("照片2", null, minio, MinioBucketName, SearchOption.AllDirectories,
                       @"^([\s\S]*)123([\s\S]*)(\.\w+)$")
                   .SearchAsync())
{
    Console.WriteLine($"{fileInfo.FileName}-----{fileInfo.Extension}---{fileInfo.DirectoryFullPath}-----{fileInfo.MimeType}");
    await Task.Delay(0);
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 167 4/21/2025
1.0.4 104 4/12/2025
1.0.3 166 4/10/2025
1.0.2 161 4/8/2025
1.0.1 345 3/24/2025