-1

Currently I have as my file path

 @"S:\Temporary Shared Space\Project\Boyscout3\Data\full_pack.txt"

I want it to be just "full_pack.txt".

I tried this code on the bottom but it appears to not be working for me:

If someone could please help I would appreciate it.

string fileName =@"S:\Temporary Shared Space\Project\Boyscout\Data\full_pack.txt";
string path = "full_pack.txt";
string result;
result = System.IO.Path.GetFileName(fileName);
Console.WriteLine("GetFileName('{0}') returns '{1}'", fileName, result);

result = System.IO.Path.GetFileName(path);
Console.WriteLine("GetFileName('{0}') returns '{1}'", path, result);

//filename shorter for den1
string fileName1 =@"S:\Temporary Shared Space\Project\Boyscout3\Data\den1.txt";
string path1 = "den1.txt";
string result1;

result1 = System.IO.Path.GetFileName(fileName1);
Console.WriteLine("GetFileName('{0}') returns '{1}'", fileName1, result1);

result1 = System.IO.Path.GetFileName(path1);
Console.WriteLine("GetFileName('{0}') returns '{1}'", path1, result1);

//Making a list for full_pack
List<string> listFullPack = new List<string>();
string line;
StreamReader sr = new StreamReader("full_pack.txt");//this is where things don't work. 
while ((line = sr.ReadLine()) != null)////When the full address is in, the code works, 
{                            //but when I replace it with full_pack.txt, 
    listFullPack.Add(line); //it can't find the file.
}
sr.Close();
Tom
  • 16,842
  • 17
  • 45
  • 54
  • 1
    are you familiar with the `File.IO` methods for example `GetFileName` have you looked at any of the `System.IO` methods on MSDN – MethodMan May 27 '15 at 16:25

1 Answers1

0

The line StreamReader sr = new StreamReader("full_pack.txt"); will look in the executable directory for this file. You need top append the full path to the file name.

You are using the wrong method from the library.

Try System.IO.Path.GetFileName and see the docs.

THBBFT
  • 1,161
  • 1
  • 13
  • 29