FileExists Error

Posted on 2006-03-29
Last Modified: 2010-04-16
Hi you experts.

I have a file that has ".." in it's name and for that i think FileExists cannot see the file even if it's there.
How can i prevent this? Is there another way to make sure tha a file exists?
Question by:adktd
    LVL 34

    Accepted Solution

    This worked for me:

          System.IO.FileInfo file = new System.IO.FileInfo("C:/");
    LVL 10

    Expert Comment

    File.Exists works as well

    using System.IO;

    MessageBox.Show(File.Exists("C:\\a..N.txt").ToString() );
    LVL 96

    Expert Comment

    by:Bob Learned
    What about this--'..\..\test.txt'?  This file would have to exist 2 directories up from the current directory.

    LVL 5

    Expert Comment

    I'm not sure about this problem, I've encountered FileExists fails in another scenario. might be related to this prob.

    If you have a folder with trailing space char, file.exists fails for anything in that path. Now, you can't make a folder like this ("j2sdk1.4.1_01 " - notice last whitespace) in Winxp anymore, such folder names must have been created in older Windows or non-Win OS. Even winexplorer failes to show properties of any file in such path.

    @adktd, let me know if winexporer can show props of you file. if it does, it could be some coding error. if it can't, its an OS bug.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now