Today when I was trying to decompile .apk file using WinRAR, I got an error and unzipping terminated. After that when I am trying to delete the folder I am getting an error that I don't have ownership of folder even though I am providing administrator permission.
Both file and parent folder of the file in the image gives an error when I try to delete it.
Then I tried doing the same using cmd in administrator mode by a command:
rm -d test
output :: rm: cannot unlink `test': Not owner
I also tried the following command to recursively delete files in a folder:
rm -r test
output:rm: WARNING: Circular directory structure.
This almost certainly means that you have a corrupted file system.
NOTIFY YOUR SYSTEM MANAGER.
The following two directories have the same inode number:test
`test/ '
So I tried the following command to delete recursive file structure,
rm -rfd test
output: rm: cannot unlink `test': Not owner
All the above methods I used are either from StackOverflow or Microsoft QnA page but nothing seems to work.
I tried all this in safe mode also. But still, I get the same error. Twice I also got an error with an error code of 0x80070091
I already tried taking ownership of folder using takeown command.
takeown /f test /r
Output:
SUCCESS: The file (or folder): "C:\Users\mandar\Desktop\test" now owned by user "MANDAR_SADYE\mandar".
SUCCESS: The file (or folder): "C:\Users\mandar\Desktop\test\ " now owned by user "MANDAR_SADYE\mandar".
I tried all the possible solutions I could find but nothing seems to work.
If anyone has any suggestion regarding this issue then please post it as answer or comment as you see fit. Thank you in advance.
Best Answer
Your problem is that you have a file system entry with a name containing only a space (
test\
, note the space after the backslash). This is technically possible in NTFS, but is not at all permitted in Win32 and most Windows APIs will not handle it gracefully at all. They will try to strip the spaces from the ends of the file name, and then get very confused when the filename isn't there anymore and may treat it as though you're referring to the directory; this happens even if you use a format liketest\*
or" "
.There are two ways out of this within Windows itself.
\\?\
. Doing this turns off all of the Win32 rules about what is a valid file name (such as "cannot begin or end with a space"), leaving only the much smaller set of NTFS rules (cannot contain a\
or:
, for example). Note that it also turns off convenient shorthands like using relative paths; if you want to do this you must supply an absolute path (C:\Users\mandar\Desktop\test\ ) and you will need to quote it so the command line knows you meant to include that final space:del "\\?\C:\Users\mandar\Desktop\test\ "
(and yes, you should be usingcmd.exe
for this; Powershell ignores the \?\ and Unix-like shells running on Windows via MinGW or Cygwin don't use paths of the format the kernel expects).bash
(or other shell) of a WSL distro, navigate to the relevant directory (cd /mnt/c/Users/mandar/Desktop/test
) and then delete the offending file (rm ' '
) or simply the whole directory.