justdoitzZ
325 天前
按照兄弟们提供的思路,chatgpt 提供了如下代码,我再调试一下,我感觉可行了
using System.Diagnostics;
// ...
private void button2_Click(object sender, EventArgs e)
{
string path = @"c:\Work\temp\123\";
string[] suffixes = { ".avl", ".sum", ".nsm" };
FileProcessor fileProcessor = new FileProcessor();
fileProcessor.ListFilesRecursively(path, suffixes);
// 获取原始结果
List<FileInfo> sourceFileInfos = fileProcessor.FileInfos;
// 创建新的目标文件信息
List<FileInfo> targetFileInfos = fileProcessor.CreateTargetFileInfos(sourceFileInfos, ".txt");
int processesCount = 10;
for (int i = 0; i < processesCount; i++)
{
int startIdx = i * targetFileInfos.Count / processesCount;
int endIdx = (i == processesCount - 1) ? targetFileInfos.Count : (i + 1) * targetFileInfos.Count / processesCount;
var processFiles = targetFileInfos.GetRange(startIdx, endIdx - startIdx);
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "YourExecutable.exe", // 替换为实际的可执行文件名
Arguments = $"{string.Join(" ", processFiles.Select(f => $"\"{f.FilePath}\""))}", // 传递文件路径作为参数
WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath), // 设置工作目录
UseShellExecute = false,
CreateNoWindow = true,
};
Process process = new Process { StartInfo = startInfo };
process.Start();
}
}