Delete folder in C:\Users

Hi!

We’re trying to delete the following folder:

“c:\users\username\appdata\roaming\discord”

When we try this, it works fine:

folder delete “c:\users\username\appdata\roaming\discord”

The problem is that we need to delete this folder in many computers with different usernames. Is there any variable we can use so the action can be executed in all the computers?

Something like this:

folder delete “c:\users$USERNAME\appdata\roaming\discord”

Thank you!

Try folder delete “c:\users\{name of logged on user}\appdata\roaming\discord”

The one issue with using a user variable is that puts a dependacy on there being a user logged in, and also not sure if you have systems with more than 1 logged in user, how would that affect behaviour.

One approach you could use to clean all user folders regardless of a user being logged would be actionscript like below

parameter "MyFolders" = "{"%22" & concatenation "%22 %22" of pathnames of folders "\appdata\roaming\discord" of folders of folder "C:\Users" & "%22"}"
runhidden cmd.exe /c "for %a in ({parameter "MyFolders"}) do rmdir /q /s %a"

The fixlet detection could include a statement like below so it only applies to systems with the folder somewhere in the users folder hierarchy.

exists folders "\appdata\roaming\discord" of folders of folder "C:\Users"

2 Likes

You might consider using the powershell script below which will delete the discord folder on every user account on the pc not just the logged in user.

$users = Get-ChildItem C:\Users

foreach ($user in $users){

$folder1 = “C:\users” + $user + “\AppData\Roaming\discord”

Remove-Item $folder1 -Recurse -Force -ErrorAction silentlycontinue

}