You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
On Windows, Remove-Item unexpectedly fails if the target directory path happens to end in a backslash #15248
# Switch to a temporary directory.Push-Location-ea Stop ($tmpDir= (New-Item-Type Directory -Force (Join-Path Temp:/$PID)).FullName)
try {
# Create two directories with one file each in them.$null=New-Item-Type Directory -force foo1, foo2
$null=New-Item-force foo1\t.txt, foo2\t.txt
# Remove the first one with WITHOUT a trailing "\"
{ Remove-Item .\foo1 -Recurse -ErrorAction Stop } | Should -Not-Throw
# Remove the second one with WITH a trailing "\"# This is also what you'd get with tab-completion.
{ Remove-Item .\foo2\ -Recurse -ErrorAction Stop } | Should -Not-Throw
} finally {
# Clean up.Pop-Location; Remove-Item$tmpDir-Recurse
}
Expected behavior
Both tests should succeed: whether the target directory is specified with a trailing path separator or not should not make a difference.
Actual behavior
On Windows, removal fails when the target path ends in \:
Cannot remove item C:\Users\jdoe\AppData\Local\Temp\8656\foo2\: The directory is not empty.
Note:
The problem only occurs if the target dir. is non-empty.
It seems to have been introduced in v7.2.0-preview.5
Environment data
PowerShell Core v7.2.0-preview.5 on Microsoft Windows 10 Pro (64-bit; Version 20H2, OS Build: 19042.928)
changed the title [-]On Windows, Remove-Item -Recurse unexpectedly fails if the target directory path happens to end in a backslash[/-][+]On Windows, Remove-Item unexpectedly fails if the target directory path happens to end in a backslash[/+]on Apr 16, 2021
Activity
iSazonov commentedon Apr 16, 2021
I'd expect follow should works -
Remove-Item .\foo\ -Recursive.mklement0 commentedon Apr 16, 2021
iSazonov commentedon Apr 16, 2021
I manually create the tree in
c:\tmpand Remove-Item works as expected without an error.[-]On Windows, Remove-Item -Recurse unexpectedly fails if the target directory path happens to end in a backslash[/-][+]On Windows, Remove-Item unexpectedly fails if the target directory path happens to end in a backslash[/+]mklement0 commentedon Apr 16, 2021
iSazonov commentedon Apr 16, 2021
No error too.
iSazonov commentedon Apr 16, 2021
Maybe you already have a locked file in C:\Users\jdoe\AppData\Local\Temp\8656\foo\ ?
mklement0 commentedon Apr 16, 2021
iSazonov commentedon Apr 16, 2021
I wonder how our CI tests are passed.
mklement0 commentedon Apr 16, 2021
So you're now seeing the problem too?
Without having looked at them: Perhaps the particular combination at hand - non-empty target dir., trailing
\,-Recurse-isn't being tested.mklement0 commentedon Apr 16, 2021
iSazonov commentedon Apr 17, 2021
It is a regression after #14902 (again symlinks 😄).
mklement0 commentedon Apr 17, 2021
Thanks for digging.
I've hidden most of my previous comments.