-1

我想做一个软件,但我真的不知道如何跟踪这些事情。

这个想法是这样的:

  1. 我选择一个文件夹
  2. 给出最大行数(例如 300000)
  3. 给一个线/包(例如8000)

软件必须这样做。转到文件夹中的每个文件(我设法完成它直到这里,大声笑)打开每个文件并保存他的行。如果 file1.txt 有例如 3000 行,将它们保存到一个文件中,转到下一个文件,如果第二个文件有 2000 行,也保存它,直到我有 8000 行到一个包中。找到 8000 行后,保存文件,如“packet1.txt”,转到下一个文件,依此类推……直到在这种情况下,所有行都达到最大行数(300 000)。

这是代码:

if (!path(folderBrowserDialog1.SelectedPath))
    MessageBox.Show("Please select a folder!");
else if ((textBox1.Text != "") && (textBox2.Text != "") && (textBox4.Text!=""))
{
    folder = folderBrowserDialog1.SelectedPath;
    maxlinks = int.Parse(textBox1.Text);
    packetlink = int.Parse(textBox2.Text);
    //  apikey = textBox4.Text;
    foreach (string file in Directory.GetFiles(folder))
    {

    }
}
else
    MessageBox.Show("Please check your input!");

PS:路径功能只检查目录是否被选中。

有人可以给出一些想法吗?

4

1 回答 1

0

尝试这个:

http://msdn.microsoft.com/en-us/library/aa287535(v=vs.71).aspx

所以

if (!path(folderBrowserDialog1.SelectedPath))
    MessageBox.Show("Please select a folder!");
else if ((textBox1.Text != "") && (textBox2.Text != "") && (textBox4.Text!=""))
{
    folder = folderBrowserDialog1.SelectedPath;
    maxlinks = int.Parse(textBox1.Text);
    packetlink = int.Parse(textBox2.Text);
    //  apikey = textBox4.Text;
    foreach (string file in Directory.GetFiles(folder))
    {
        int counter = 0;
        string line;

        // Read the file and display it line by line.
        System.IO.StreamReader file = 
           new System.IO.StreamReader(file);
        while((line = file.ReadLine()) != null && counter < 30000)
        {
            Console.WriteLine (line);
            counter++;
        }

        file.Close();
    }

}
else
{
    MessageBox.Show("Please check your input!");
}
于 2012-06-22T12:23:19.120 回答