windows 如何删除名称以点(“.”)结尾的文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4075753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete a folder that name ended with a dot (".")?
提问by jerry.liu
I got some folders created by malware whose name ended with a dot like C:\a.\
or C:\b.\
, etc.
我得到了一些由恶意软件创建的文件夹,它们的名称以一个点结尾,例如C:\a.\
或C:\b.\
等。
I found a solution that can remove such folder with command rd /q /s "C:\a.\"
but if I call win API RemoveDirectory
, it returns ERROR_FILE_NOT_FOUND
.
我找到了一个可以使用命令删除此类文件夹的解决方案,rd /q /s "C:\a.\"
但如果我调用 win API RemoveDirectory
,它会返回ERROR_FILE_NOT_FOUND
.
And I just wonder how to write a function to delete such directory, thanks
我只是想知道如何编写一个函数来删除这样的目录,谢谢
I test on my own Windows XP SP3 system like this
我像这样在我自己的 Windows XP SP3 系统上测试
create a folder C:\>mkdir a..\\\
and I cannot double click to access this folder. and I can remove with command rd /q /s "C:\a.\"
创建一个文件夹C:\>mkdir a..\\\
,但我无法双击访问该文件夹。我可以用命令删除 rd /q /s "C:\a.\"
what Windows system API(s) that rd /q /s
command call?
该rd /q /s
命令调用哪些 Windows 系统 API ?
回答by Skilldrick
Here's a solution to this problem:
rd /s "\?\C:\Documents and Settings\User\Desktop\Annoying Folder."
回答by Cody Gray
Solution:When you call RemoveDirectory, make sure that you prefix the path with the string "\\?\
".
解决方案:当您调用 RemoveDirectory 时,请确保在路径前加上字符串“ \\?\
”。
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).
解释:它与点有关。根据 MSDN,在某些情况下您可能无法删除 NTFS 卷上的文件或文件夹,特别是当文件名在 Win32 命名空间中无效时(这就是为什么您无法使用Windows 资源管理器中的常规方法)。
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.
如果文件名包含无效名称(例如,文件名有尾随空格或尾随句点或文件名仅由空格组成),您可能无法删除文件。要解决此问题,请使用使用适当内部语法的工具来删除文件。您可以使用“\\?\”语法和一些工具来操作这些文件,例如:del "\\?\c:\path_to_file_that 包含尾随 space.txt "此问题的原因与原因 4 类似。但是,如果您使用典型的 Win32 语法打开名称中带有尾随空格或尾随句点的文件,则在打开实际文件之前会去除尾随空格或句点。因此,如果您在同一文件夹中有两个名为“AFile.txt”和“AFile.txt”的文件(注意文件名后面的空格),如果您尝试使用标准 Win32 调用打开第二个文件,您将打开代替第一个文件。类似地,如果您有一个名称仅为“”(空格字符)的文件,并且您尝试使用标准 Win32 调用打开它,则您会打开该文件的父文件夹。在这种情况下,如果您尝试更改这些文件的安全设置,您可能无法执行此操作,或者您可能会意外更改不同文件的设置。
回答by AmirHossein
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.
我已经把这个贴在 SU 上,我也决定把它贴在这里。这是实现这一目标的最简单、最快和最简单的方法。我现在嘲笑它是多么简单。
- Install WinRAR
- Follow the Step by Step procedure from pictures:
- 安装WinRAR
- 按照图片中的分步程序进行操作:
I myself had WinRaR installed so I decided to demonstrate the workaround in it.
This workaround is also possible by using 7zip.
我自己安装了 WinRaR,所以我决定在其中演示解决方法。
使用 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!
我应该提到的另一件事是,问题似乎是由使用 windows 资源管理器引起的,任何其他文件浏览器(如 winrar 文件浏览器本身、ftp 资源管理器等)都会将此文件视为正常文件。
您可以尝试使用任何文件浏览器,只需删除这些文件,而不必费心将它们归档!干杯!
回答by Laurynas Lazauskas
If you have git installed (you can get ir from here) then it is as simple as:
如果你已经安装了 git(你可以从这里获取 ir ),那么它很简单:
- Navigate File Explorer to location where problematic folder is located.
- Context menu (right mouse button) > Git Bash Here.
rm -rf Foldername./
- 将文件资源管理器导航到有问题的文件夹所在的位置。
- 上下文菜单(鼠标右键)> Git Bash Here。
rm -rf Foldername./
回答by neorobin
When you see the name is "a.", but the actual name is "a.."
当您看到名称为“a.”,但实际名称为“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"
)
回答by Aryan
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.
我使用了“ WinRar”一个简单的 RAR、ZIP 处理器。您可以使用任何类型的文件名编辑器。只需在WinRar中打开文件所在的目录,右键单击要重命名的文件/文件夹并填写新名称后选择重命名即可。
回答by RyuuGan
回答by kreker
Use bash rm command from Ubuntu on Windows 10
在 Windows 10 上使用来自 Ubuntu 的 bash rm 命令
回答by mer2329
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)
如果您还想在 bash 中保留文件选项。
您将需要适用于 Linux 的 Windows 子系统(我安装了 Ubuntu)
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'.
以保留文件。打开命令提示符并 cd 到文件或文件夹所在的位置。
现在输入“ bash
”,
这将在提示中打开 bash。现在输入mv '[folder or file you want to move]' '[new name (can include path)]'
(还有更多 mv 所以如果你想阅读它的所有选项,使用'man mv'这将打开它的手册页(然后使用 q 返回到 bash))
mv 命令是 move 的缩写,但它的具有重命名事物的次要功能。
同样在 bash 中使用“单引号”而不是普通的“双引号”,因为 bash 需要“单引号”。
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.
这是一个例子。假设您的文件夹名为“ data 1.
”,位于c:\users
(因此错误文件夹的完整路径为c:\users\data 1.
1. 使用任何方法打开命令提示符
2. 输入cd c:\users
3. 现在键入bash
这会在您之前所在的文件夹中加载 bash
4. 最后键入mv 'data 1.' 'data 1'
5。该文件夹现在可以访问,您可以选择删除它。