Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

System.IO.File.Exists not working

$
0
0

So, here's the issue I am facing. I have no clue why this simple thing is not working for me -

Here's my simple code

public static bool deleteFile(List<string> fileNames, string folderPath)
{
 foreach (string s in fileNames)
 {
  string pathString = System.IO.Path.Combine(folderPath, s);
  if (System.IO.File.Exists(pathString))
  {
   System.IO.File.Delete(pathString);
   return true;
  }
  else
  {
   Console.WriteLine(String.Format(@"File {0} in folder path {1} does not exist", s, folderPath));
   return false;
  }
 }
}

public static void main()
{
 string folderPath = @"C:\TFS\Documents\Test Folder";
 List<string> file = new List<string>();
    file.Add("Sample.docx");
 deleteFile(file, folderPath);
}

I am seeing that the program shows that the file doesn't exist when I can see the file in the directory.

What am I doing wrong?

Thanks for all the help in advance!


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles