Reputation: 403
string[] files = File.ReadAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt");
foreach (string file in files)
{
}
I want to to remove from the file UploadedVideoFiles.txt the first line.
Upvotes: 0
Views: 105
Reputation: 2729
var lines = File.ReadAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt");
File.WriteAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt", lines.Skip(1));
Upvotes: 1
Reputation: 35477
Old school (without LINQ) is to start iterating at index 1.
for (int i = 1; i < files.Length; ++i)
{
// do something with files[i], which is a line in the file.
}
Upvotes: 0
Reputation: 10764
Use Enumerable.Skip Linq extension method:
string[] files = File.ReadAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt").Skip(1).ToArray();
File.WriteAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt", files);
Upvotes: 0
Reputation: 5135
Using LINQ is the best approach in this case:
foreach (string file in files.Skip(1))
Upvotes: 3