Delete Read-Only file


#1

Hello, could you please tell me how to delete a file which has attribute Read-only set as True? I can delete this file manually without problems but the activity “Delete file” always throws UnauthorizedAccessException. Is there some workaround how to delete such file or how to modify file’s attribute?


#2

Only way i found is to use “Invoke Power Shell” activity with following command (IsScript must be checked):
“Set-ItemProperty ‘full file name’ -name:IsReadOnly -value:0”+ vbCrLF +
"Remove-Item ‘full file name’"
To delete entire folder all files’ attributes must be changed prior the deletion and then this command can be used:
“Remove-Item -path ‘folder path’ -recurse -confirm:0”


#3

Alternatively, you can use the InvokeMethod activity before the Delete to clear the read only flag by calling the SetAttributes static method of the System.IO.File type.


#4

thanks Mihai, this helps


#5

Guys where are deleted files removed by Delete activity ? Is there any way to undo it ? I deleted all my my desktop files :frowning: