3

I copied some files using macOS Finder to an exFAT partition so I ended up having lots of hidden dot files in the folder. I can delete them without any issue in Explorer, but whenever I run the del command I always get "Could Not Find" error in cmd even though they can be listed with dir

D:\>dir /a "D:\._DSCF0035.JPG"
 Volume in drive D is Data
 Volume Serial Number is 7802-8428

 Directory of D:\

12/04/2021  10:08 SA             4.096 ._DSCF0035.JPG

D:\>del "D:\._DSCF0035.JPG"
Could Not Find D:\._DSCF0035.JPG

D:\>del /f "D:\._DSCF0035.JPG"
Could Not Find D:\._DSCF0035.JPG

In PowerShell I also got error if deleting normally but if I add -Force to Remove-Item it succeeded

PS D:\> ls -Force "D:\._DSCF0009.JPG"


    Directory: D:\


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a-h--         4/12/2021  10:08 AM           4096 ._DSCF0009.JPG


PS D:\> rm "D:\._DSCF0009.JPG"
rm : Cannot remove item D:\._DSCF0009.JPG: You do not have sufficient access rights to perform this
operation.
At line:1 char:1
+ rm "D:\._DSCF0009.JPG"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (D:\._DSCF0009.JPG:FileInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
PS D:\> rm -Force "D:\._DSCF0009.JPG" # Succeeded
PS D:\>

I tried starting cmd and PowerShell in normal and elevated mode but the same thing happens. Why does it fail in every case except Explorer and PowerShell with -Force?

2
  • What version of Windows did this happen on? Example: Windows 10 1903 – JG7 Apr 17 at 2:50
  • @JG7 Windows 10 build 21359 – phuclv Apr 17 at 2:52
4

Your file has the h attribute set; meaning it is hidden. That's why you can't delete when using del or Remove-Item unless you use the -Force parameter. From Remove-Item:

Forces the cmdlet to remove items that cannot otherwise be changed, such as hidden or read-only files or read-only aliases or variables.

5
  • In Explorer, the items are only visbie (and thus deletable) wen the "Show Hidden" option is selected. So "Show Hidden" puts Explorer in a persistent -Force state for browsing & deletion. – Keith Miller Apr 17 at 6:38
  • But why doesn't it work in cmd when I also specify the /F option? – phuclv Apr 17 at 7:03
  • I think as the file is hidden del /f does not work, but del /a:h works. – Reddy Lutonadio Apr 17 at 7:33
  • @ReddyLutonadio I tried del /a and it works – phuclv Apr 17 at 10:23
  • @phuclv just seen your comment so removed my answer – DuncG Apr 17 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.