12

I am following this tutorial from MSDN.

There's something I saw in the code that I can't understand

    private void PopulateTreeView()
    {
        TreeNode rootNode;

        DirectoryInfo info = new DirectoryInfo(@"../.."); // <- What does @"../.." mean?
        if (info.Exists)
        {
            rootNode = new TreeNode(info.Name);
            rootNode.Tag = info;
            GetDirectories(info.GetDirectories(), rootNode);
            treeView1.Nodes.Add(rootNode);
        }
    }
Xel
  • 540
  • 2
  • 8
  • 27
  • http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx – zerkms Feb 22 '12 at 04:53
  • 3
    possible duplicate of [What's the @ in front of a string in C#?](http://stackoverflow.com/questions/556133/whats-the-in-front-of-a-string-in-c) – M.Babcock Feb 22 '12 at 04:54

4 Answers4

21

@ is for verbatim string, so that the string is treated as is. Especially useful for paths that have a \ which might be treated as escape characters ( like \n)

../.. is relative path, in this case, two levels up. .. represents parent of current directory and so on.

manojlds
  • 290,304
  • 63
  • 469
  • 417
8

.. is the container directory. So ../.. means "up" twice.
For example if your current directory is C:/projects/a/b/c then ../.. will be C:/projects/a

shift66
  • 11,760
  • 13
  • 50
  • 83
  • 1
    Not the downvoter but `.` represents the current directory and `..` would be one level up, maybe someone was upset reading your first line and hence voted you down – V4Vendetta Feb 22 '12 at 05:42
  • Pretty sure it's because the OP *knows* what ../.. means; he didn't know what @ means. It's the combination that threw him off, especially because the @ is redundant here anyway. – Ernest Friedman-Hill Feb 22 '12 at 12:00
4

example E:\Software\file\folder

/ is the root of the current drive. ./ is the current director. ../ is the parent of the current directory. that is ->E:\ ../.. is relative path, in this case, two levels up. to get folder just write "../../folder"

Akash das
  • 371
  • 4
  • 9
3

new DirectoryInfo(@"../..") means "a directory two levels above the current one".

The @ denotes a verbatim string literal.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523