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?

phuclv
  • 26,555
  • 15
  • 113
  • 235

1 Answers1

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.

Reddy Lutonadio
  • 17,120
  • 4
  • 14
  • 35