Append multiple text files into single file and Rename the file [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hello I have multiple text files in one location and they have names as shown below:-
A_L_PRTD_021345.txt , A_L_PRTD_432124 and so on...
I want to append the contents into single file and want to rename the single file as L_PRTD_Currentdate>.txt
How is it possible?
Can you please show some code for it?

First read each file using File.ReadAllLines(fileName) ;
Then create a single file and append the contents of other files in it
string[] contents1 = File.ReadAllLines(fileName1) ;
string[] contents2 = File.ReadAllLines(fileName2) ;
File.Create(newFileNameHere) ;
File.WriteAllLines(newFileNameHere, contents1) ;
File.AppendAllLines(newFileNameHere, contents2) ;
and so on ...
Check the following documentation of the functions, if you need help:-
http://msdn.microsoft.com/en-us/library/92e05ft3(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/dd383691(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/s2tte0y1(v=vs.110).aspx

Related

how to use StreamReader in C# to read only entries over a specific length to a list? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
when using StreamReader in C# to load a txt file into a list, i assume that using a simple "If" the string's length is over a particular length, it will add it to the list. can anyone provide C# code for this? this IS homework, but it's NOT a C# class. the instructor would gladly provide this if i asked this specifically. thx.
the txt file is a dictionary of ~280,000 words, one per line. very simple move to turn into a list, but i'm wondering about getting words at least 2 characters long.
Just use LINQ to give you a subset.
List<string> lines = File.ReadLines(filename)
.Where(l => l.Length > specifiedWordLength)
.ToList();

write values in a .txt file in C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I m new to programming and i m looking for source code which can write and add values to a text file using C# programming. The code should ask the user to input values in the console window. the values are :-
Enter Name, Enter account no., Enter Balance
the output should get stored in the text file in the following format :-
Mark,10001,230000
Steve,10002,32987
Bruce,10003,23454
William,10004,23454
I would appreciate some help.
string name;
int number1,number2;
// Read name, number1, number2 from Console
//.....
//.....
//Saving in a file:
string outputFileName = #"c:\myfile.txt"
StreamWriter sw = new StreamWriter(outputFileName);
sw.WriteLine(string.Format("{0},{1},{2}",name,number1,number2));
sw.Close();

Line Number of String [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
StreamReader reader = new StreamReader("C:\\ABC\\XYZ.txt");
I am reading a file using streamreader, the file is a HL7 file
MSH|^~\&|ABC|000|ABC|ABC|0000||ABC|000|A|00
PID|1|000|||ABC||000|A||||||||||
PV1|1|O||||||||||||||||||||||||||||||||||||||||||
OBR|1|||00||00|00|||||||||||ABC|00|0|0||||A|||||00||ABC|7ABC||ABC
OBX|1|ABC|ABC|1|SGVsbG8=
I need to find the line number of OBX, the file has character delimiters at the end of each line e.g. MSH|^~\&|ABC|000|ABC|ABC|0000||ABC|000|A|00*CR*LF
The reason I need this is that I need to get the Base64 inside the OBX field, and write it out as a file. my reader will always be a stream, I cannot use the file stream. The above code was an example, the following implementation is to be made in BizTalk and the file I will reading will be stream because that's how BizTalk allows me to access the information in of my file.
var lineNum = File.ReadLines(fname)
.Select((s, line) => new { s, line })
.First(x => x.s.StartsWith("OBX|"))
.line;

How do I split a path at specific directory? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following path...
'X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials\'
I want to split it at the directory 'Assets' and end up with...
'Assets\Models\FullBuilding\Materials\'
The directory 'Assets' will not always be in the same place in the path. How can I do this? Thanks.
Lets say your string is
string completePath = "X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials\";
string subPath = completePath.subString(completePath.IndexOf(#"Assets\"));
Please note that if your path contains multiple instances of Assests it will substring from first instance of Asset.
you can use path.IndexOf, you can use the str.SubString(str.IndexOf("\assetse")), you can do alot of things. playing with string is kinda fun...
most of the things you want to do with strings you can find on google anyway

Directory structure - what path should I use? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have created a WindowsApp.exe under Application\Setup folder. Now I want to create a Database under Application\Database folder from WindowsApp.exe
What should be the path given to the filename here?
try
Path.Combine(Environment.CurrentDirectory, "Database\\db1.mdb")
Edit
since you want the parent folder you can go up one folder by doing
Path.Combine(Environment.CurrentDirectory.Substring(Environment.CurrentDirectory.LastIndexOf("\\")), "Database\\db1.mdb")
Edit 2
if you want the Application folder even if its N times above the current folder then you can reach it by doing this
var index = Environment.CurrentDirectory.IndexOf(Environment.CurrentDirectory.IndexOf("ApplicationRootFolderName"),"\\")
var AppRootPath = Environment.CurrentDirectory.Substring(0,index);
Edit 3
As mentioned by Michael its better to get the parent folder using this way
Directory.GetParent(Environment.CurrentDirectory).FullName

Categories