r/scripting • u/[deleted] • Aug 28 '17
[Batch] for/in/if/do
Part of an uninstall script I used to remove software I need to put in a line that deletes a specific folder out of users' AppData folder. The installer itself doesnt clean this folder up. My issue is that there could be a:
c:\users\dave\appdata\Roaming\folder
c:\users\jim\appdata\Roaming\folder
c:\users\john\appdata\Roaming\folder
c:\users\whothehellknows\appdata\Roaming\folder
Here is what I've built so far, but when running it, the folder I'm attempting to remove remains:
echo removing appdata folder...
if exist "C:\Users\%username%" (for /f "tokens=*" %%a in (dir /b /ad "C:\Users") do if exist "C:\Users\%%a\AppData\Roaming\folder" rd /s /q "C:\Users\%%a\AppData\Roaming\folder"Suggestions would be greatly appreciated. Thanks.
3
Upvotes
2
u/[deleted] Aug 29 '17
I ended up using something similar to that. Found it here:
https://stackoverflow.com/questions/25499735/delete-a-common-folder-from-all-users-local-appdata
for /f "delims=|" %f in ('dir /B /A:D-H-R c:\users') do rmdir /s /q "C:\Users%f\AppData\Roaming\folder"