Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use the Path class when working with file paths, and use the File and Directory class when working with actual files and folders.</p> <pre><code>string str1=@"C:/Documents and Settings/All Users/Desktop/AccessData FTK Imager.lnk"; string str2=@"C:/Documents and Settings/All Users/Start Menu/Programs/AccessData"; string str3=@"C:/Documents and Settings/Administrator/Desktop/AccessData FTK Imager.exe:Zone.Identifier"; Console.WriteLine(Path.GetFileName(str1)); Console.WriteLine(Path.GetFileName(str2)); Console.WriteLine(Path.GetFileName(str3)); </code></pre> <p>outputs:</p> <pre><code>AccessData FTK Imager.lnk AccessData Zone.Identifier &lt;-- it chokes here because of the : </code></pre> <p>This class operates on strings, as I do not have those particular files and/or folders on my system. Also it's impossible to determine whether <code>AccessData</code> is meant to be a folder or a file without an extension.</p> <p>I could use some common sense and declare everything with an extension to be a file (<code>Path.GetFileExtension</code> can be used here) and everything else to be a folder.<br> Or I could just check it the string in question is indeed a file or a folder on my machine using (<code>File.Exists</code> and <code>Directory.Exists</code> respectively).</p> <pre><code>if (File.Exists(str2)) Console.WriteLine("It's a file"); else if (Directory.Exists(str2)) Console.WriteLine("It's a folder"); else Console.WriteLine("It's not a real file or folder"); </code></pre>
 

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