Stefano Borini
Stefano Borini

Reputation: 143925

Cannot remove files from powershell, but can from the GUI

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?

Upvotes: 9

Views: 9767

Answers (2)

IamAunixGOD
IamAunixGOD

Reputation: 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

Upvotes: -1

Jeepm
Jeepm

Reputation: 314

Did you run Powershell as Administrator rights?

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

Upvotes: 20

Related Questions