Search code examples
windowsqtqdir

Cannot remove a directory with bad name, created accidentally by Qt in Windows 10


I've created a directory using QDir but the given name had two dots in the end, Qt created this directory although its bad naming, and now my windows 10 OS cannot operate on this invalid directory.

I cannot do any operation on it. I've done these:

  • run chkdsk with fixing flags, ...
  • run check disk utility in drive properties
  • trying to remove it from command line in cmd and powershell
  • trying to delete the directory using QDir

What should I do?

enter image description here


Solution

  • Try

    RemoveDirectoryW(L"\\\\?\\C:\\full\\path\\to\\dir..");
    

    Explanation: besides enabling the long path handling as documented, the \\?\ prefix bypasses Win32 path processing, passing the path directly to NT API, so it would go directly to NT kernel.

    Make sure you use RemoveDirectoryW, not RemoveDirectoryA, a fully qualified path, and backwards slashes '\\' (not /). Due to C++ esaping in string literals, \\?\C:\path becomes "\\\\?\\C:\\path".