EDN Admin
Well-known member
On the right of my project in the solution explorer right click on the mouse on my project name add existing item > in the list i didnt file *.txt so i did select all *.*
And selected the text file i wanted so now in the solution explorer in the end i see: video_formats.txt now how can i use the text file in my code ?
In the line: StreamReader sr = new StreamReader(); i want to use the text file as existing item something like: StreamReader sr = new StreamReader(video_formats);<br/>
But cant figure out how to do it.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.IO;
<span style="color:Blue; namespace ConsoleApplication1
{
<span style="color:Blue; class Program
{
<span style="color:Blue; static <span style="color:Blue; void Main(<span style="color:Blue; string[] args)
{
<span style="color:Blue; int y;
FileInfo fi;
<span style="color:Blue; string[] newDest_files;
<span style="color:Blue; string f;
<span style="color:Blue; string line;
StreamReader sr = <span style="color:Blue; new StreamReader();
<span style="color:Blue; while ((line = sr.ReadLine()) != <span style="color:Blue; null)
{
f = line;
newDest_files = Directory.GetFiles(Environment.CurrentDirectory, f);
<span style="color:Blue; for (y = 0; y < newDest_files.Length; y++)
{
fi = <span style="color:Blue; new FileInfo(newDest_files[y]);
<span style="color:Blue; string newFolder = Path.Combine(fi.DirectoryName, fi.Name + <span style="color:#A31515; "_Directory");
<span style="color:Blue; if (!Directory.Exists(newFolder))
Directory.CreateDirectory(newFolder);
Console.WriteLine(<span style="color:#A31515; "processed: " + newDest_files.Length + <span style="color:#A31515; " files");
File.Move(fi.FullName, Path.Combine(newFolder, fi.Name));
}
<span style="color:Blue; if (newDest_files.Length == 0)
{
Console.WriteLine(f+<span style="color:#A31515; " No files found in the current directory!");
}
}
sr.Close();
Console.WriteLine(<span style="color:#A31515; "Done! Press any key to exit...");
Console.ReadKey();
}
}
}
[/code]
<hr class="sig danieli
View the full article
And selected the text file i wanted so now in the solution explorer in the end i see: video_formats.txt now how can i use the text file in my code ?
In the line: StreamReader sr = new StreamReader(); i want to use the text file as existing item something like: StreamReader sr = new StreamReader(video_formats);<br/>
But cant figure out how to do it.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.IO;
<span style="color:Blue; namespace ConsoleApplication1
{
<span style="color:Blue; class Program
{
<span style="color:Blue; static <span style="color:Blue; void Main(<span style="color:Blue; string[] args)
{
<span style="color:Blue; int y;
FileInfo fi;
<span style="color:Blue; string[] newDest_files;
<span style="color:Blue; string f;
<span style="color:Blue; string line;
StreamReader sr = <span style="color:Blue; new StreamReader();
<span style="color:Blue; while ((line = sr.ReadLine()) != <span style="color:Blue; null)
{
f = line;
newDest_files = Directory.GetFiles(Environment.CurrentDirectory, f);
<span style="color:Blue; for (y = 0; y < newDest_files.Length; y++)
{
fi = <span style="color:Blue; new FileInfo(newDest_files[y]);
<span style="color:Blue; string newFolder = Path.Combine(fi.DirectoryName, fi.Name + <span style="color:#A31515; "_Directory");
<span style="color:Blue; if (!Directory.Exists(newFolder))
Directory.CreateDirectory(newFolder);
Console.WriteLine(<span style="color:#A31515; "processed: " + newDest_files.Length + <span style="color:#A31515; " files");
File.Move(fi.FullName, Path.Combine(newFolder, fi.Name));
}
<span style="color:Blue; if (newDest_files.Length == 0)
{
Console.WriteLine(f+<span style="color:#A31515; " No files found in the current directory!");
}
}
sr.Close();
Console.WriteLine(<span style="color:#A31515; "Done! Press any key to exit...");
Console.ReadKey();
}
}
}
[/code]
<hr class="sig danieli
View the full article