批处理文件,用于删除终端服务器上用户配置文件的Firefox缓存



我想运行一个批处理文件,删除终端服务器上所有用户配置文件的firefox缓存文件夹。就像ICSweep删除所有用户的临时互联网文件一样。

Location: C:users *username*appdatalocalmozillafirefoxprofiles *random*.defaultcache

问题在于不同的用户名文件夹,并且firefoxprofiles下的子文件夹的名称包含"随机字符.default",并且对于所有用户都是不同的。

这可以用批处理文件完成吗?或者我需要像vb脚本之类的东西吗?

如果这可以做到,我也会这样做的谷歌Chrome缓存

C:users *username*appdatalocalgooglechromeuser datadefaultcache

是的,这可以做到。它只需要一些简单的批处理递归。这个脚本已经完全可以使用了。当准备删除缓存文件夹时,只需将echo命令替换为del命令。

:: Hide Commands
@echo off
setlocal EnableExtensions
:: Parse the Local AppData sub path
call :Expand xAppData "%%LocalAppData:%UserProfile%=%%"
set "xFirefox=mozillafirefoxprofiles"
set "xChrome=googlechromeuser data"
:: Start at the User directory
pushd "%UserProfile%.."
:: Loop through the Users
for /D %%D in (*) do if exist "%%~fD%xAppData%" (
    rem Check for Firefox
    if exist "%%~fD%xAppData%%xFirefox%" (
        pushd "%%~fD%xAppData%%xFirefox%"
        rem Loop through the Profiles
        for /D %%P in (*) do (
            if exist "%%~fPcache" echo "%%~fPcache"
        )
        popd
    )
    rem Check for Chrome
    if exist "%%~fD%xAppData%%xChrome%" (
        pushd "%%~fD%xAppData%%xChrome%"
        rem Loop through the Profiles
        for /D %%P in (*) do (
            if exist "%%~fPcache" echo "%%~fPcache"
        )
        popd
    )
)
popd
goto End

::::::::::::::::::::::::::::::
:Expand <Variable> <Value>
if not "%~1"=="" set "%~1=%~2"
goto :eof

:End
endlocal
pause

更新注释

要使用Firefox profiles.ini文件,将上面的检查Firefox部分替换为以下内容:

rem Check for Firefox INI
if exist "%%~fD%xAppData%%xFirefox%profiles.ini" (
    pushd "%%~fD%xAppData%%xFirefox%"
    rem Loop through the Profiles
    for /f "tokens=1,* delims==" %%L in (profiles.ini) do (
        if /i "%%~L"=="Path" if exist "%%~fMcache" echo "%%~fMcache"
    )
    popd
)

以上脚本的更新版本,仅Firefox:

:: Hide Commands
rem @echo off
setlocal EnableExtensions
:: Parse the Local AppData sub path
call :Expand xAppData "%%LocalAppData:%UserProfile%=%%"
set "xFirefox=mozillafirefoxprofiles"
set "xChrome=googlechromeuser data"
:: Start at the User directory
pushd "%UserProfile%.."
:: Loop through the Users
for /D %%D in (*) do if exist "%%~fD%xAppData%" (
    rem Check for Firefox
    rem if exist "%%~fD%xAppData%%xFirefox%" (
    if exist  "%%~fD%xAppData%%xLocal%%xMozilla%%xFirefox%" (
        rem pushd "%%~fD%xAppData%%xFirefox%"
        pushd "%%~fD%xAppData%%xLocal%%xMozilla%%xFirefox%"
        rem Loop through the Profiles
        for /D %%P in (*) do (
            if exist "%%~fPcache2" del /F /Q /S "%%~fPcache2"
        )
        popd
    )
)
popd
goto End

::::::::::::::::::::::::::::::
:Expand <Variable> <Value>
if not "%~1"=="" set "%~1=%~2"
goto :eof

:End
endlocal
pause

最新更新