1

I wrote some codes to create a directory named "E:\hkhkhkhk\...." in c++. It actually created "...." iteratively. And the parent directory "hkhkhkhk" cannot be removed.

I was wondering how the system explains "....".

The code is as below, execute it in virtual machine.

#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
    if (!CreateDirectoryA("E:\\hkhkhkhk\\....\\", NULL))
        cout << GetLastError() << endl;

    getchar();
    return 0;
}

Josh

marked as duplicate by grawity, Kamil Maciorowski, Worthwelle, music2myear, n8te Jun 14 at 11:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Windows doesn't allow programs to use paths ending with a dot; whenever a program tries to access such a path, all dots are quietly removed from the end.

You bypassed this restriction when creating the directory since your path actually ends with a backslash, but other programs (e.g. Windows Explorer) don't do this.

So when you double-click the directory in Explorer, it tries to change to E:\hkhkhkhk\.... but actually gets E:\hkhkhkhk\ (which is the same as the parent directory), creating the illusion of infinite recursion when in reality you never go anywhere at all.

  • 1
    Your explanation is very helpful, thx alot! – joshqin Jun 12 at 4:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.