如何删除名称以“ .”结尾的文件夹?

我得到了一些由恶意软件创建的文件夹,其名称以一个点结束,如 C:\a.\C:\b.\等。

我找到了一个解决方案,可以用命令 rd /q /s "C:\a.\"删除这样的文件夹,但如果我调用 win API RemoveDirectory,它将返回 ERROR_FILE_NOT_FOUND

我只是想知道如何编写一个函数来删除这样的目录,谢谢

我在我自己的 WindowsXPSP3系统上进行了这样的测试

创建一个文件夹 C:\>mkdir a..\\\和我不能双击访问这个文件夹。我可以用命令 rd /q /s "C:\a.\"删除

rd /q /s命令调用的 Windows 系统 API 是什么?

71549 次浏览

Try to use unlocker program to delete files and folders that you can't delete normally.

Solution: When you call RemoveDirectory, make sure that you prefix the path with the string "\\?\".


Explanation: It has everything to do with the dot. According to MSDN, there are certain cases where you may not be able to delete a file or folder on an NTFS volume, specifically when the file name is invalid in the Win32 name space (which is why you are unable to open the file using the normal methods in Windows Explorer).

You may not be able to delete a file if the file name includes an invalid name (for example, the file name has a trailing space or a trailing period or the file name is made up of a space only). To resolve this issue, use a tool that uses the appropriate internal syntax to delete the file. You can use the "\\?\" syntax with some tools to operate on these files, for example:
del "\\?\c:\path_to_file_that contains a trailing space.txt "
The cause of this issue is similar to Cause 4. However, if you use typical Win32 syntax to open a file that has trailing spaces or trailing periods in its name, the trailing spaces or periods are stripped before the actual file is opened. Therefore, if you have two files in the same folder named "AFile.txt" and "AFile.txt " (note the space after the file name), if you try to open the second file by using standard Win32 calls, you open the first file instead. Similarly, if you have a file whose name is just " " (a space character) and you try to open it by using standard Win32 calls, you open the file's parent folder instead. In this situation, if you try to change security settings on these files, you either may not be able to do this or you may unexpectedly change the settings on different files. If this behavior occurs, you may think that you have permission to a file that actually has a restrictive ACL.

(Source: http://support.microsoft.com/?kbid=320081)

Here's a solution to this problem:

rd /s "\\?\C:\Documents and Settings\User\Desktop\Annoying Folder."

When you see the name is "a.", but the actual name is "a.."

Try this:

rd /q /s "C:\a..\"

And you can try explore the folder by this code:

for /f "tokens=3 delims=<>" %%a in ('dir /ad /x "C:\*" ^| findstr " a\.\.$"') do (
for /f "tokens=1" %%b in ("%%a") do start "" "%%~fb"
)

I used "WinRar" A simple RAR, ZIP processor. You can use any sort of file name editor. Just open the directory where your file is into WinRar and select rename after right clicking the file/folder you want to rename and fill in the new name.

Ive posted this on SU and I decided to post it here too. Its the simplest and fastest and easiest way to achieve this. I am now laughing at how much simple it is.

  1. Install WinRAR
  2. Follow the Step by Step procedure from pictures:
  3. enter image description here
  4. enter image description here
  5. enter image description here
  6. enter image description here

I myself had WinRaR installed so I decided to demonstrate the workaround in it.
This workaround is also possible by using 7zip.

One another thing I should mention is that, as it seems the problem is caused by using windows explorer and any other file browser (like winrar file browser itself, ftp explorers etc.) will treat this files as normal.
You could try using any file browser and simply delete those files and not bother archiving them though! Cheers!

If you have git installed (you can get ir from here) then it is as simple as:

  1. Navigate File Explorer to location where problematic folder is located.
  2. Context menu (right mouse button) > Git Bash Here.
  3. rm -rf Foldername./

Use bash rm command from Ubuntu on Windows 10

if you want to keep the files theres options in bash as well.
you will require the Windows Subsystem for Linux package (i have Ubuntu installed)

to keep the files. open a command prompt and cd over to where the file or folder is located.
now type "bash"
this will open bash in the prompt. now enter mv '[folder or file you want to move]' '[new name (can include path)]' (theres more to mv so if you want to read up on all of its options use 'man mv' this will open its manual page (then use q to return to bash))
the mv command is short for move, but its has a secondary function of renaming things.
also in bash use 'single quotes' and not a normal "double quote", as bash expects 'single quotes'.

heres a example. assume your folder is named "data 1." located in c:\users (so the full path to the error folder is c:\users\data 1.
1. open command prompt using any method
2. enter cd c:\users
3. now type bash this loads bash in the folder you previously were in
4. finally type mv 'data 1.' 'data 1'
5. the folder is now accessible and you can choose to delete it.

If you need to keep the data you can also use the \\?\ trick for renaming the folder.

ren "\\?\C:\Documents and Settings\User\Desktop\Annoying Folder." "\\?\C:\Documents and Settings\User\Desktop\Annoying Folder"

This is an ideal solution if you need to know what is inside the folder or if the data is important.

This works in both Command Prompt and PowerShell.