用“.”删除项目在文件名中不起作用

Remove-Item with "." in filenames doesn't work

我的 Powershell 脚本检查文件是否存在。如果存在,则删除现有文件。然后保存一个同名的新文件。 当我的文件名(和路径)中没有点(“。”)时,它工作得很好。我认为 -LiteralPath 是解决方案,但它不起作用,不知道为什么。 Test-Path 似乎有效,但 Remove-Item 无效。

 $xlsFile = "R:\Temp Place i.Bay.\ComeOn 37 Place i.Bay. user_finance.xlsx"

 if (Test-Path -LiteralPath $xlsFile)
        {
            try {
                Write-Host "TestPath positiv, try to delete"
                Remove-Item -LiteralPath $xlsFile -ErrorAction "Stop"
            } catch {
                Write-Warning $_.Exception.Message
            }

            try {
                $xlsObj.ActiveWorkbook.SaveAs($xlsFile);
            } catch {
                Write-Warning $_.Exception.Message
            }

        }
        else
        {
            Write-Host "TestPath negativ"
            $xlsObj.ActiveWorkbook.SaveAs($xlsFile);
        };

Powershell 2.0,R: 是网络路径。

感谢

在 windows 中不允许以点结尾的文件夹名称:

Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. However, it is acceptable to specify a period as the first character of a name. For example, ".temp".

https://msdn.microsoft.com/en-us/library/aa365247.aspx