如何删除 windows 上以点 (.) 结尾的目录?

How to remove a directory that ends with a dot (.) on windows?

我错误地创建了一个文件,我无法删除它。如果你安装了7-Zip,你就可以生产它。如果没有,安装也很简单。

文件的创建方式如下:

PS C:\temp> mkdir abc
PS C:\temp> cd abc

PS C:\temp\abc> & 'C:\Program Files-Zipz.exe' a -spf .\DuoWindowsLogon.admx,.\en-us\DuoWindowsLogon.adml

Creating archive: .\DuoWindowsLogon.admx,.\en-us\DuoWindowsLogon.adml

后来,我了解到我应该输入的正确命令是:

& 'C:\Program Files-Zipz.exe' a abc.7z -spf DuoWindowsLogon.admx en-us\DuoWindowsLogon.adml

发现错误后,尝试删除错误创建的目录:

PS C:\temp\abc> ls
d-----       11/15/2020  11:09 PM                DuoWindowsLogon.admx,.

PS C:\temp\abc> ls D*
ls : Could not find item C:\temp\abc\DuoWindowsLogon.admx,..

PS C:\temp\abc> ls | rm
rm : Cannot find path 'C:\temp\abc\DuoWindowsLogon.admx,.' because it does not exist.

PS C:\temp\abc> rm *
rm : An object at the specified path C:\temp\abc\DuoWindowsLogon.admx,. does not exist.

PS C:\temp\abc> cd ..
PS C:\temp> rm -recurse abc
rm : Could not find a part of the path 'C:\temp\abc\DuoWindowsLogon.admx,'.

如您所见,没有任何效果。我还尝试了文件资源管理器 (GUI),它也不起作用。我怎样才能删除目录?

PS:

我在 CMD 提示符下尝试了“del /s”,它没有产生错误,但文件没有被删除:

c:\>del /s c:\temp\abc
c:\temp\abc\*, Are you sure (Y/N)? Y

c:\>dir c:\temp\abc
11/15/2020  11:09 PM    <DIR>          DuoWindowsLogon.admx,.

您可以删除以“.”结尾的目录。通过在其前面加上 \?\

因此,在您的情况下,您可以使用:

Remove-Item `\?\C:\temp\abc\DuoWindowsLogon.admx,.` -Recurse

此处记录:You can't delete a file or a folder on an NTFS file system volume

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.