using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
string mydocpath =
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
StringBuilder sb = new StringBuilder();
foreach (string txtName in Directory.EnumerateFiles(mydocpath,"*.txt"))
{
using (StreamReader sr = new StreamReader(txtName))
{
sb.AppendLine(txtName.ToString());
sb.AppendLine("= = = = = =");
sb.Append(sr.ReadToEnd());
sb.AppendLine();
sb.AppendLine();
}
}
using (StreamWriter outfile =
new StreamWriter(mydocpath + @"\AllTxtFiles.txt"))
{
outfile.Write(sb.ToString());
}
}
}
C++
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Collections::Generic;
ref class Program
{
public:
static void Main()
{
String^ mydocpath =
Environment::GetFolderPath(Environment::SpecialFolder::MyDocuments);
StringBuilder^ sb = gcnew StringBuilder();
for each (String^ txtName in Directory::EnumerateFiles(mydocpath, "*.txt"))
{
StreamReader^ sr = gcnew StreamReader(txtName);
sb->AppendLine(txtName->ToString());
sb->AppendLine("= = = = = =");
sb->Append(sr->ReadToEnd());
sb->AppendLine();
sb->AppendLine();
sr->Close();
}
StreamWriter^ outfile = gcnew StreamWriter(mydocpath + "\\AllTxtFiles.txt");
outfile->Write(sb->ToString());
outfile->Close();
}
};
int main()
{
Program::Main();
}
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......