Cannot delete folder?

hello,

I want to delete folder but error denied as below.

On the right side, I entered the normal path:
C:\Users\xxxxxxxxxxxxx

But the system shows that it cannot delete the path:
\\?\C:\Users\xxxxxxxxxxxxx

I’m not sure where the prefix \\?\ came from.

hi @Stef_99 ,

The \?\ prefix is automatically added by UiPath to support extended-length paths in Windows—this is normal and not the cause of the issue.

The “Access denied” error is typically due to permissions or the folder being in use. If you’re trying to delete something like C:\Users<user> , it may fail because:

  • The folder is currently in use (e.g., active user profile)
  • The robot is not running with sufficient privileges

Suggestions:

  • Run the process as Administrator
  • Ensure no processes are using the folder
  • Avoid deleting system/user profile directories; target subfolders instead

This should resolve the issue.

Regards

Hi @Stef_99 ,

Looks like a permission issue , Run the BOT in Debug mode ,once BOT fails please check if you can delete the file manually ?

@Christopher_R I tested deleting the folder manually via Windows Explorer, and it can be deleted normally.

@Stef_99

Try logging the folder path you are trying to delete using Log message. This will give you the exact folder path.

Also try selecting the folder path from the icon -

@ashokkarale Yes, I choose by this icon but same error.

@Stef_99 : If you can delete the folder manually but UiPath can’t, seems like a File lock

Please use the below in Invoke code(VB.NET) keep it before the delete activity, This will release the file lock if any

GC.Collect
GC.WaitForPendingFinalizers

Alright @Stef_99.

Try updating the package UiPath.System.Activities to latest possible version. If already on latest, try downgrading it.

@ashokkarale same error

@Christopher_R Same error.

Please try this VB Code

Imports System.IO
Try
    GC.Collect()
    GC.WaitForPendingFinalizers()
    'If folder exists, delete it forcefully
    If Directory.Exists(folderPath) Then
        Directory.Delete(folderPath, True)
    End If
Catch ex As Exception
    Throw New Exception("Failed to delete folder: " & ex.Message)
End Try