本文介绍了如何动态命名文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要这样的文件名:Nr [文件中的第一个数字] - [文件中的最后一个数字] .txt。
我有:
I want to have the file names like this: Nr[first number in file]-[last number in file].txt.
this I have:
static void Main(string[] args)
{
const int linesPerFile = 10;
string path = @"G:\Folder";
const string destinationFileName = @"G:\Folder\File-Part-{0}.txt";
//string fileName = "File";
var maxNumberOfFiles = 10;
Stopwatch timer = new Stopwatch();
var fileCounter = 0;
if (!Directory.Exists(path))
{
DirectoryInfo di = Directory.CreateDirectory(path);
}
var destiNationFile = new StreamWriter(string.Format(destinationFileName, fileCounter + 1));
try
{
// foreach (var bank in BankAcoutNumbers.BANS.Take(100))
//{
var lineCounter = 0;
string line;
while (fileCounter <= maxNumberOfFiles)
{
timer.Start();
foreach (var bank in BankAcoutNumbers.BANS.Take(100))
{
if (lineCounter % linesPerFile == 0)
{
//lineCounter = 0;
destiNationFile.Flush();
destiNationFile.Dispose();
destiNationFile = new StreamWriter(string.Format(destinationFileName, fileCounter + 1));
fileCounter++;
}
destiNationFile.WriteLine(bank);
lineCounter++;
}
fileCounter++;
//}
}
timer.Stop();
// Console.WriteLine(BankAcoutNumbers.BANS.Count());
Console.WriteLine(timer.Elapsed.Seconds);
}
catch (Exception)
{
throw;
}
// Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
所以第一个文件包含数字:
So the first file contains the numbers:
100000002
100000010
100000029
100000037
100000045
100000053
100000061
100000088
100000096
100000118
所以文件名必须是:Nr [100000002] - [100000118] .txt
谢谢
so the file name has to be then: Nr[100000002]-[100000118].txt
Thank you
推荐答案
这篇关于如何动态命名文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!