9

I am trying to remove files I generated using powershell and del, but I get this message

del : Cannot remove item C:\Users\stefano.borini\<redacted>\.tox\py36\Include\fakepq.h: You do not have sufficient access rights to perform this operation.
At line:1 char:1
+ del .\.tox\

+ ~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (fakepq.h:FileInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
del : Cannot remove item C:\Users\stefano.borini\<redacted>\.tox\py36\Include\fakesql.h: You do not have sufficient access rights to perform this operation.

However, I can right click the items and delete them from the windows explorer without any problem. Why?

3
  • @marsze it's not the point. I am not running the GUI in admin mode, and I created those files using tox while in PS. I want to understand the problem, not workaround it Commented May 28, 2019 at 11:45
  • 2
    Any chance these files are hidden? I was able to reproduce that when I made the file/folder hidden and tried deleting them. In that case, just add -Force. Commented May 28, 2019 at 13:14
  • 3
    As noted - possibly the file has the read-only, hidden, or system attributes set. You could check this by (Get-Item "pathname").Attributes. If it has any of those attributes, you would need to add -Force to your command line (see help Remove-Item -Parameter Force for details). Commented May 28, 2019 at 14:24

2 Answers 2

20

Did you run Powershell as Administrator rights?

If so, you can try to add "-force" to your command.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the correct answer and should be checkmarked.
-1

I have found the solution to this issue. This is specifically referring to the files that are created with Windows 10 FileHistory where users are posting issues with it all over.

When you look at your files in PowerShell doing a "dir" command on them, you'll see something like this.

Directory: D:\FileHistory\XXX\BT-XX\Data\C\Users\XXXX\Documents

dir Out*

Mode LastWriteTime Length Name


d----- 2022-09-30 12:11 OUTLOOK.BACKUP.20220910 d----- 2022-09-30 12:46 Outlook Rules d----- 2022-09-30 12:46 Outlook Personal Folders d----- 2022-09-30 13:25 Outlook Files -ar--- 2016-03-13 13:08 19673 Outlook Rules 20160313 (2022_09_30 13_30_15 UTC).rwz -ar--- 2012-09-13 13:39 28488 Outlook Rules 20120913 (2022_09_30 13_30_15 UTC).rwz -ar--- 2022-09-30 15:27 33919878144 Outlook (2022_09_30 19_44_57 UTC).pst -ar--- 2022-10-03 18:31 33940448256 Outlook (2022_10_03 22_32_14 UTC).pst -ar--- 2022-10-04 02:41 33940448256 Outlook (2022_10_04 06_54_55 UTC).pst -ar--- 2022-10-04 12:50 33940448256 Outlook (2022_10_04 16_50_50 UTC).pst

The -ar---- is the problem. The 'a' is for archive, and the 'r' is for READ-ONLY!!!!!!!!! WHY DO THEY DO THIS TO US?!?!?

If you try to delete one of these files from PowerShell with the rm command, it will not allow it and give you this message:

… Cannot remove item ……………… You do not have sufficient access rights to perform this operation. At line:1 char:1

  • rm '.\Outlook (2022_10_03 22_32_14 UTC).pst ...
  •   + CategoryInfo          : PermissionDenied: (D:\FileHistory\...35_35 UTC.ost :FileInfo) [Remove-Item], IOException
      + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
    
    

You can add the -force to your rm command and it WILL delete it immediately.

In Windows Explorer, look at the properties of the "FileHistory" folder. It will have [X] READ-ONLY checked. If you un-check it, it'll say: You have chosen to make the following attribute changes: unset read-only

Do you want to apply this change to this folder only, or do you want to apply it to all subfolders and files as well?

When I select the default "Apply changes to this folder, subfolders and files", it will go through the entire structure and turn off read-only on the files.

When you go back to that directory in PowerShell, they will now look like this:

Mode LastWriteTime Length Name


d----- 2022-09-30 12:11 OUTLOOK.BACKUP.20220910 d----- 2022-09-30 12:46 Outlook Rules d----- 2022-09-30 12:46 Outlook Personal Folders d----- 2022-09-30 13:25 Outlook Files -a---- 2016-03-13 13:08 19673 Outlook Rules 20160313 (2022_09_30 13_30_15 UTC).rwz -a---- 2012-09-13 13:39 28488 Outlook Rules 20120913 (2022_09_30 13_30_15 UTC).rwz -a---- 2022-09-30 15:27 33919878144 Outlook (2022_09_30 19_44_57 UTC).pst -a---- 2022-10-03 18:31 33940448256 Outlook (2022_10_03 22_32_14 UTC).pst -a---- 2022-10-04 02:41 33940448256 Outlook (2022_10_04 06_54_55 UTC).pst -a---- 2022-10-04 12:50 33940448256 Outlook (2022_10_04 16_50_50 UTC).pst

Now you can run the FileHistory "Clean up versions", select whatever parameter under "Delete files:" (Older than 1 year… etc…)

This should work. But why do we have to do this extra step? Why doesn't Windows know that if we can create the file, we should be able to delete it.

Let me know if anyone finds anything else out.

ATB, Josef

1 Comment

Needs formatting. Otherwise log output is not separated from answer itself and looks garbled and bloated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.