none
System.IO.File.Exist returns always true RRS feed

  • Question

  • In my program, check whether file exists or not using System.IO.Exists(strFile).

    However returns true in case of strFile = @"\test.cfg"

    Can anybody give me any idea about this?

    Wednesday, February 27, 2019 6:52 PM

All replies

  • Hello,

    I assume you mean System.IO.File.Exists. 

    If I run this code at this time don't have that file I expected (and do) hit the else.

    var fileName = @"\test.cfg";
    if (File.Exists(fileName))
    {
        Console.WriteLine("Exists");
    }
    else
    {
        Console.WriteLine("No exists");
    }
    Perhaps you can add more details like where is the path e.g. on a network or local machine etc.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, February 27, 2019 6:59 PM
    Moderator
  • Hi Jeff0803,

    Thank you for posting here.

    >>System.IO.Exists(strFile)

    System.IO has two Exist method: File.Exists(String) Method and Directory.Exists(String) Method.

    Based on my test, I could reproduce your situation when the file do not exist returns true. Please provide more details.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 28, 2019 3:15 AM
    Moderator