Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming that the file/directory actually exists, you can use the two static methods:</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx" rel="nofollow noreferrer">System.IO.File.Exists()</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/system.io.directory.exists.aspx" rel="nofollow noreferrer">System.IO.Directory.Exists()</a></li> </ul> <p>Both accept a single string argument and returns a boolean value if the file/directory exists.</p> <p>Another case is when you have a path that <em>does not</em> refer to an existing file/directory in the file system - maybe it points to some kind of "virtual file/directory" in a database, or the path points to a file/directory that used to exists, but is now (possibly) deleted. In this case, you will have to define the distinction of "file like paths" and "directory like paths" yourself. I can think of two approaches:</p> <ul> <li>A: Directory paths ends with a directory seperator (as suggested by Wael Dalloul)</li> <li>B: File paths have an extension seperator in their last path token</li> </ul> <p>Lets test the two approaches on a couple of sample input strings:</p> <ul> <li><code>c:\windows\</code> is a directory in both cases</li> <li><code>c:\windows</code> is a directory only when using approach B</li> <li><code>c:\windows\notepad.exe</code> is a file in both cases</li> <li><code>c:\windows\system32\drivers\etc\hosts</code> is a file only in approach A</li> </ul> <p>As pointed out by these examples, none of the two approaches are guaranteed to give the expected answers in all cases, <em>unless</em> you are able to control exactly how the paths are designed from the beginning.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload