Home > Software engineering >  Script. Delete temp mozilla firefox
Script. Delete temp mozilla firefox

Time:04-22

The point is that I have to create a script for my school that deletes all the temporary ones from Mozilla Firefox, with a batch script in Windows 10. The most complex thing about this is that the mozilla path has a folder that has a different "Prefix" on each computer, in my case it is wvbrz602.default-release. (Ruta completa sería: C:\Users\dmarmol\AppData\Local\Mozilla\Firefox\Profiles\wvbrz602.default-release)

What I have done has been a loop that iterates for each user and stores it in the variable in which it iterates "%%a" In this way I obtain each user, once each user is obtained, I do a dir obtaining the prefix of the containing folder of the Firefox profile of each user in a .txt document (Since the prefix is ​​different for each user) After that prefix obtained in the .txt of each user I add it to a variable (The problem is that, apparently they don't like it) And finally I make a del of the temporary of each user.

This is my code:

@ECHO on
SETLOCAL EnableDelayedExpansion
rem TASKKILL /F /IM mozilla.exe /T

for /f %%a in ('dir c:\Users /b') do>%%a.txt (
dir /b "C:\Users\%%a\AppData\Local\Mozilla\Firefox\Profiles\*.default-release"
set /p contenedorFor=<"%%a".txt
del C:\Users\%%a\AppData\Local\Mozilla\Firefox\Profiles\%contenedorFor%\cache2

)
exit /b 0

I show a snapshot of the exit the code. https://img.codepudding.com/202204/eb8363e67b0b46bebe120aab0cec56b6.png

CodePudding user response:

You can simply test if the file exists. Here, the result will be echo'ed only where you need to replace echo with rmdir or del accordingly:

@echo off
for /d %%i in ("%systemdrive%\Users\*") do (
     for /f "delims=" %%a in ('dir /b /a:d "%%~i\AppData\Local\Mozilla\Firefox\Profiles\" 2^>nul ^|findstr "default-release"') do del /Q "%%~i\AppData\Local\Mozilla\Firefox\Profiles\%%~nxa\Cache2\*"
)
  • Related